@@ -50,20 +50,17 @@ public partial class RedisNativeClient
50
50
internal long deactivatedAtTicks ;
51
51
public DateTime ? DeactivatedAt
52
52
{
53
- get
54
- {
55
- return deactivatedAtTicks != 0
56
- ? new DateTime ( Interlocked . Read ( ref deactivatedAtTicks ) , DateTimeKind . Utc )
57
- : ( DateTime ? ) null ;
58
- }
53
+ get => deactivatedAtTicks != 0
54
+ ? new DateTime ( Interlocked . Read ( ref deactivatedAtTicks ) , DateTimeKind . Utc )
55
+ : ( DateTime ? ) null ;
59
56
set
60
57
{
61
- var ticksValue = value == null ? 0 : value . Value . Ticks ;
58
+ var ticksValue = value ? . Ticks ?? 0 ;
62
59
Interlocked . Exchange ( ref deactivatedAtTicks , ticksValue ) ;
63
60
}
64
61
}
65
62
66
- public bool HadExceptions { get { return deactivatedAtTicks > 0 ; } }
63
+ public bool HadExceptions => deactivatedAtTicks > 0 ;
67
64
68
65
protected Socket socket ;
69
66
protected BufferedStream Bstream ;
@@ -81,14 +78,8 @@ public DateTime? DeactivatedAt
81
78
private int active ;
82
79
internal bool Active
83
80
{
84
- get
85
- {
86
- return Interlocked . CompareExchange ( ref active , 0 , 0 ) == YES ;
87
- }
88
- set
89
- {
90
- Interlocked . Exchange ( ref active , value ? YES : NO ) ;
91
- }
81
+ get => Interlocked . CompareExchange ( ref active , 0 , 0 ) == YES ;
82
+ set => Interlocked . Exchange ( ref active , value ? YES : NO ) ;
92
83
}
93
84
94
85
internal IHandleClientDispose ClientManager { get ; set ; }
@@ -109,8 +100,8 @@ internal bool Active
109
100
private TimeSpan retryTimeout ;
110
101
public int RetryTimeout
111
102
{
112
- get { return ( int ) retryTimeout . TotalMilliseconds ; }
113
- set { retryTimeout = TimeSpan . FromMilliseconds ( value ) ; }
103
+ get => ( int ) retryTimeout . TotalMilliseconds ;
104
+ set => retryTimeout = TimeSpan . FromMilliseconds ( value ) ;
114
105
}
115
106
public int RetryCount { get ; set ; }
116
107
public int SendTimeout { get ; set ; }
@@ -123,10 +114,7 @@ public int RetryTimeout
123
114
124
115
internal IRedisTransactionBase Transaction
125
116
{
126
- get
127
- {
128
- return transaction ;
129
- }
117
+ get => transaction ;
130
118
set
131
119
{
132
120
if ( value != null )
@@ -137,10 +125,7 @@ internal IRedisTransactionBase Transaction
137
125
138
126
internal IRedisPipelineShared Pipeline
139
127
{
140
- get
141
- {
142
- return pipeline ;
143
- }
128
+ get => pipeline ;
144
129
set
145
130
{
146
131
if ( value != null )
@@ -205,10 +190,7 @@ public RedisNativeClient()
205
190
long db ;
206
191
public long Db
207
192
{
208
- get
209
- {
210
- return db ;
211
- }
193
+ get => db ;
212
194
213
195
set
214
196
{
@@ -227,13 +209,7 @@ public void ChangeDb(long db)
227
209
SendExpectSuccess ( Commands . Select , db . ToUtf8Bytes ( ) ) ;
228
210
}
229
211
230
- public long DbSize
231
- {
232
- get
233
- {
234
- return SendExpectLong ( Commands . DbSize ) ;
235
- }
236
- }
212
+ public long DbSize => SendExpectLong ( Commands . DbSize ) ;
237
213
238
214
public DateTime LastSave
239
215
{
@@ -268,8 +244,7 @@ public string ServerVersion
268
244
{
269
245
get
270
246
{
271
- string version ;
272
- this . Info . TryGetValue ( "redis_version" , out version ) ;
247
+ this . Info . TryGetValue ( "redis_version" , out var version ) ;
273
248
return version ;
274
249
}
275
250
}
@@ -286,8 +261,7 @@ public RedisData RawCommand(params object[] cmdWithArgs)
286
261
continue ;
287
262
}
288
263
289
- var bytes = arg as byte [ ] ;
290
- if ( bytes != null )
264
+ if ( arg is byte [ ] bytes )
291
265
{
292
266
byteArgs . Add ( bytes ) ;
293
267
}
@@ -1436,8 +1410,7 @@ public byte[][] BLPop(string[] listIds, int timeOutSecs)
1436
1410
{
1437
1411
if ( listIds == null )
1438
1412
throw new ArgumentNullException ( "listIds" ) ;
1439
- var args = new List < byte [ ] > ( ) ;
1440
- args . Add ( Commands . BLPop ) ;
1413
+ var args = new List < byte [ ] > { Commands . BLPop } ;
1441
1414
args . AddRange ( listIds . Select ( listId => listId . ToUtf8Bytes ( ) ) ) ;
1442
1415
args . Add ( timeOutSecs . ToUtf8Bytes ( ) ) ;
1443
1416
return SendExpectMultiData ( args . ToArray ( ) ) ;
@@ -1471,8 +1444,7 @@ public byte[][] BRPop(string[] listIds, int timeOutSecs)
1471
1444
{
1472
1445
if ( listIds == null )
1473
1446
throw new ArgumentNullException ( "listIds" ) ;
1474
- var args = new List < byte [ ] > ( ) ;
1475
- args . Add ( Commands . BRPop ) ;
1447
+ var args = new List < byte [ ] > { Commands . BRPop } ;
1476
1448
args . AddRange ( listIds . Select ( listId => listId . ToUtf8Bytes ( ) ) ) ;
1477
1449
args . Add ( timeOutSecs . ToUtf8Bytes ( ) ) ;
1478
1450
return SendExpectMultiData ( args . ToArray ( ) ) ;
@@ -1497,19 +1469,19 @@ public byte[][] BRPopValue(string[] listIds, int timeOutSecs)
1497
1469
public byte [ ] RPopLPush ( string fromListId , string toListId )
1498
1470
{
1499
1471
if ( fromListId == null )
1500
- throw new ArgumentNullException ( " fromListId" ) ;
1472
+ throw new ArgumentNullException ( nameof ( fromListId ) ) ;
1501
1473
if ( toListId == null )
1502
- throw new ArgumentNullException ( " toListId" ) ;
1474
+ throw new ArgumentNullException ( nameof ( toListId ) ) ;
1503
1475
1504
1476
return SendExpectData ( Commands . RPopLPush , fromListId . ToUtf8Bytes ( ) , toListId . ToUtf8Bytes ( ) ) ;
1505
1477
}
1506
1478
1507
1479
public byte [ ] BRPopLPush ( string fromListId , string toListId , int timeOutSecs )
1508
1480
{
1509
1481
if ( fromListId == null )
1510
- throw new ArgumentNullException ( " fromListId" ) ;
1482
+ throw new ArgumentNullException ( nameof ( fromListId ) ) ;
1511
1483
if ( toListId == null )
1512
- throw new ArgumentNullException ( " toListId" ) ;
1484
+ throw new ArgumentNullException ( nameof ( toListId ) ) ;
1513
1485
1514
1486
byte [ ] [ ] result = SendExpectMultiData ( Commands . BRPopLPush , fromListId . ToUtf8Bytes ( ) , toListId . ToUtf8Bytes ( ) , timeOutSecs . ToUtf8Bytes ( ) ) ;
1515
1487
return result . Length == 0 ? null : result [ 1 ] ;
@@ -1981,9 +1953,9 @@ public long ZRemRangeByLex(string setId, string min, string max)
1981
1953
private static void AssertHashIdAndKey ( object hashId , byte [ ] key )
1982
1954
{
1983
1955
if ( hashId == null )
1984
- throw new ArgumentNullException ( " hashId" ) ;
1956
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
1985
1957
if ( key == null )
1986
- throw new ArgumentNullException ( " key" ) ;
1958
+ throw new ArgumentNullException ( nameof ( key ) ) ;
1987
1959
}
1988
1960
1989
1961
public long HSet ( string hashId , byte [ ] key , byte [ ] value )
@@ -2008,7 +1980,7 @@ public long HSetNX(string hashId, byte[] key, byte[] value)
2008
1980
public void HMSet ( string hashId , byte [ ] [ ] keys , byte [ ] [ ] values )
2009
1981
{
2010
1982
if ( hashId == null )
2011
- throw new ArgumentNullException ( " hashId" ) ;
1983
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2012
1984
2013
1985
var cmdArgs = MergeCommandWithKeysAndValues ( Commands . HMSet , hashId . ToUtf8Bytes ( ) , keys , values ) ;
2014
1986
@@ -2051,9 +2023,9 @@ public byte[] HGet(byte[] hashId, byte[] key)
2051
2023
public byte [ ] [ ] HMGet ( string hashId , params byte [ ] [ ] keys )
2052
2024
{
2053
2025
if ( hashId == null )
2054
- throw new ArgumentNullException ( " hashId" ) ;
2026
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2055
2027
if ( keys . Length == 0 )
2056
- throw new ArgumentNullException ( " keys" ) ;
2028
+ throw new ArgumentNullException ( nameof ( keys ) ) ;
2057
2029
2058
2030
var cmdArgs = MergeCommandWithArgs ( Commands . HMGet , hashId . ToUtf8Bytes ( ) , keys ) ;
2059
2031
@@ -2075,11 +2047,11 @@ public long HDel(byte[] hashId, byte[] key)
2075
2047
public long HDel ( string hashId , byte [ ] [ ] keys )
2076
2048
{
2077
2049
if ( hashId == null )
2078
- throw new ArgumentNullException ( " hashId" ) ;
2050
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2079
2051
if ( keys == null )
2080
- throw new ArgumentNullException ( " keys" ) ;
2052
+ throw new ArgumentNullException ( nameof ( keys ) ) ;
2081
2053
if ( keys . Length == 0 )
2082
- throw new ArgumentException ( " keys" ) ;
2054
+ throw new ArgumentException ( nameof ( keys ) ) ;
2083
2055
2084
2056
var cmdWithArgs = MergeCommandWithArgs ( Commands . HDel , hashId . ToUtf8Bytes ( ) , keys ) ;
2085
2057
return SendExpectLong ( cmdWithArgs ) ;
@@ -2094,31 +2066,31 @@ public long HExists(string hashId, byte[] key)
2094
2066
public long HLen ( string hashId )
2095
2067
{
2096
2068
if ( string . IsNullOrEmpty ( hashId ) )
2097
- throw new ArgumentNullException ( " hashId" ) ;
2069
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2098
2070
2099
2071
return SendExpectLong ( Commands . HLen , hashId . ToUtf8Bytes ( ) ) ;
2100
2072
}
2101
2073
2102
2074
public byte [ ] [ ] HKeys ( string hashId )
2103
2075
{
2104
2076
if ( hashId == null )
2105
- throw new ArgumentNullException ( " hashId" ) ;
2077
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2106
2078
2107
2079
return SendExpectMultiData ( Commands . HKeys , hashId . ToUtf8Bytes ( ) ) ;
2108
2080
}
2109
2081
2110
2082
public byte [ ] [ ] HVals ( string hashId )
2111
2083
{
2112
2084
if ( hashId == null )
2113
- throw new ArgumentNullException ( " hashId" ) ;
2085
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2114
2086
2115
2087
return SendExpectMultiData ( Commands . HVals , hashId . ToUtf8Bytes ( ) ) ;
2116
2088
}
2117
2089
2118
2090
public byte [ ] [ ] HGetAll ( string hashId )
2119
2091
{
2120
2092
if ( hashId == null )
2121
- throw new ArgumentNullException ( " hashId" ) ;
2093
+ throw new ArgumentNullException ( nameof ( hashId ) ) ;
2122
2094
2123
2095
return SendExpectMultiData ( Commands . HGetAll , hashId . ToUtf8Bytes ( ) ) ;
2124
2096
}
@@ -2141,7 +2113,7 @@ public virtual IRedisSubscription CreateSubscription()
2141
2113
public byte [ ] [ ] Subscribe ( params string [ ] toChannels )
2142
2114
{
2143
2115
if ( toChannels . Length == 0 )
2144
- throw new ArgumentNullException ( " toChannels" ) ;
2116
+ throw new ArgumentNullException ( nameof ( toChannels ) ) ;
2145
2117
2146
2118
var cmdWithArgs = MergeCommandWithArgs ( Commands . Subscribe , toChannels ) ;
2147
2119
return SendExpectMultiData ( cmdWithArgs ) ;
@@ -2156,7 +2128,7 @@ public byte[][] UnSubscribe(params string[] fromChannels)
2156
2128
public byte [ ] [ ] PSubscribe ( params string [ ] toChannelsMatchingPatterns )
2157
2129
{
2158
2130
if ( toChannelsMatchingPatterns . Length == 0 )
2159
- throw new ArgumentNullException ( " toChannelsMatchingPatterns" ) ;
2131
+ throw new ArgumentNullException ( nameof ( toChannelsMatchingPatterns ) ) ;
2160
2132
2161
2133
var cmdWithArgs = MergeCommandWithArgs ( Commands . PSubscribe , toChannelsMatchingPatterns ) ;
2162
2134
return SendExpectMultiData ( cmdWithArgs ) ;
@@ -2181,17 +2153,17 @@ public RedisPipelineCommand CreatePipelineCommand()
2181
2153
public long GeoAdd ( string key , double longitude , double latitude , string member )
2182
2154
{
2183
2155
if ( key == null )
2184
- throw new ArgumentNullException ( " key" ) ;
2156
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2185
2157
if ( member == null )
2186
- throw new ArgumentNullException ( " member" ) ;
2158
+ throw new ArgumentNullException ( nameof ( member ) ) ;
2187
2159
2188
2160
return SendExpectLong ( Commands . GeoAdd , key . ToUtf8Bytes ( ) , longitude . ToUtf8Bytes ( ) , latitude . ToUtf8Bytes ( ) , member . ToUtf8Bytes ( ) ) ;
2189
2161
}
2190
2162
2191
2163
public long GeoAdd ( string key , params RedisGeo [ ] geoPoints )
2192
2164
{
2193
2165
if ( key == null )
2194
- throw new ArgumentNullException ( " key" ) ;
2166
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2195
2167
2196
2168
var members = new byte [ geoPoints . Length * 3 ] [ ] ;
2197
2169
for ( var i = 0 ; i < geoPoints . Length ; i ++ )
@@ -2209,7 +2181,7 @@ public long GeoAdd(string key, params RedisGeo[] geoPoints)
2209
2181
public double GeoDist ( string key , string fromMember , string toMember , string unit = null )
2210
2182
{
2211
2183
if ( key == null )
2212
- throw new ArgumentNullException ( " key" ) ;
2184
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2213
2185
2214
2186
return unit == null
2215
2187
? SendExpectDouble ( Commands . GeoDist , key . ToUtf8Bytes ( ) , fromMember . ToUtf8Bytes ( ) , toMember . ToUtf8Bytes ( ) )
@@ -2219,7 +2191,7 @@ public double GeoDist(string key, string fromMember, string toMember, string uni
2219
2191
public string [ ] GeoHash ( string key , params string [ ] members )
2220
2192
{
2221
2193
if ( key == null )
2222
- throw new ArgumentNullException ( " key" ) ;
2194
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2223
2195
2224
2196
var cmdWithArgs = MergeCommandWithArgs ( Commands . GeoHash , key . ToUtf8Bytes ( ) , members . Map ( x => x . ToUtf8Bytes ( ) ) . ToArray ( ) ) ;
2225
2197
return SendExpectMultiData ( cmdWithArgs ) . ToStringArray ( ) ;
@@ -2228,7 +2200,7 @@ public string[] GeoHash(string key, params string[] members)
2228
2200
public List < RedisGeo > GeoPos ( string key , params string [ ] members )
2229
2201
{
2230
2202
if ( key == null )
2231
- throw new ArgumentNullException ( " key" ) ;
2203
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2232
2204
2233
2205
var cmdWithArgs = MergeCommandWithArgs ( Commands . GeoPos , key . ToUtf8Bytes ( ) , members . Map ( x => x . ToUtf8Bytes ( ) ) . ToArray ( ) ) ;
2234
2206
var data = SendExpectComplexResponse ( cmdWithArgs ) ;
@@ -2260,7 +2232,7 @@ public List<RedisGeoResult> GeoRadius(string key, double longitude, double latit
2260
2232
bool withCoords = false , bool withDist = false , bool withHash = false , int ? count = null , bool ? asc = null )
2261
2233
{
2262
2234
if ( key == null )
2263
- throw new ArgumentNullException ( " key" ) ;
2235
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2264
2236
2265
2237
var args = new List < byte [ ] >
2266
2238
{
@@ -2331,7 +2303,7 @@ public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double
2331
2303
bool withCoords = false , bool withDist = false , bool withHash = false , int ? count = null , bool ? asc = null )
2332
2304
{
2333
2305
if ( key == null )
2334
- throw new ArgumentNullException ( " key" ) ;
2306
+ throw new ArgumentNullException ( nameof ( key ) ) ;
2335
2307
2336
2308
var args = new List < byte [ ] >
2337
2309
{
@@ -2401,10 +2373,7 @@ public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double
2401
2373
2402
2374
internal bool IsDisposed { get ; set ; }
2403
2375
2404
- public bool IsManagedClient
2405
- {
2406
- get { return ClientManager != null ; }
2407
- }
2376
+ public bool IsManagedClient => ClientManager != null ;
2408
2377
2409
2378
public virtual void Dispose ( )
2410
2379
{
@@ -2458,20 +2427,17 @@ private void SafeConnectionClose()
2458
2427
try
2459
2428
{
2460
2429
// workaround for a .net bug: http://support.microsoft.com/kb/821625
2461
- if ( Bstream != null )
2462
- Bstream . Close ( ) ;
2430
+ Bstream ? . Close ( ) ;
2463
2431
}
2464
2432
catch { }
2465
2433
try
2466
2434
{
2467
- if ( sslStream != null )
2468
- sslStream . Close ( ) ;
2435
+ sslStream ? . Close ( ) ;
2469
2436
}
2470
2437
catch { }
2471
2438
try
2472
2439
{
2473
- if ( socket != null )
2474
- socket . Close ( ) ;
2440
+ socket ? . Close ( ) ;
2475
2441
}
2476
2442
catch { }
2477
2443
0 commit comments