@@ -315,7 +315,7 @@ public long StrLen(string key)
315
315
return SendExpectLong ( Commands . StrLen , key . ToUtf8Bytes ( ) ) ;
316
316
}
317
317
318
- public void Set ( string key , byte [ ] value )
318
+ public void Set ( string key , byte [ ] value , int ? expirySeconds = null , long ? expiryMs = null , bool ? exists = null )
319
319
{
320
320
if ( key == null )
321
321
throw new ArgumentNullException ( "key" ) ;
@@ -324,103 +324,28 @@ public void Set(string key, byte[] value)
324
324
if ( value . Length > OneGb )
325
325
throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
326
326
327
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ) ;
328
- }
329
-
330
- public void SetOnlyIfKeyExists ( string key , byte [ ] value )
331
- {
332
- if ( key == null )
333
- throw new ArgumentNullException ( "key" ) ;
334
- value = value ?? new byte [ 0 ] ;
335
-
336
- if ( value . Length > OneGb )
337
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
338
-
339
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyExists ) ;
340
- }
341
-
342
- public void SetOnlyIfKeyDoesNotExist ( string key , byte [ ] value )
343
- {
344
- if ( key == null )
345
- throw new ArgumentNullException ( "key" ) ;
346
- value = value ?? new byte [ 0 ] ;
347
-
348
- if ( value . Length > OneGb )
349
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
350
-
351
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyDoesNotExist ) ;
352
- }
353
-
354
- public void SetOnlyIfKeyExistsExpireInMilliseconds ( string key , byte [ ] value , long expireInMs )
355
- {
356
- if ( key == null )
357
- throw new ArgumentNullException ( "key" ) ;
358
- value = value ?? new byte [ 0 ] ;
359
-
360
- if ( value . Length > OneGb )
361
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
362
-
363
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyExists , Commands . ExpireInMilliseconds , expireInMs . ToUtf8Bytes ( ) ) ;
364
- }
365
-
366
- public void SetOnlyIfKeyDoesNotExistExprireInMillseconds ( string key , byte [ ] value , long expireInMs )
367
- {
368
- if ( key == null )
369
- throw new ArgumentNullException ( "key" ) ;
370
- value = value ?? new byte [ 0 ] ;
371
-
372
- if ( value . Length > OneGb )
373
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
374
-
375
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyDoesNotExist , Commands . ExpireInMilliseconds , expireInMs . ToUtf8Bytes ( ) ) ;
376
- }
377
-
378
- public void SetOnlyIfKeyExistsExpire ( string key , byte [ ] value , int expireInSeconds )
379
- {
380
- if ( key == null )
381
- throw new ArgumentNullException ( "key" ) ;
382
- value = value ?? new byte [ 0 ] ;
383
-
384
- if ( value . Length > OneGb )
385
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
386
-
387
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyExists , Commands . ExpireInSeconds , expireInSeconds . ToUtf8Bytes ( ) ) ;
388
- }
389
-
390
- public void SetOnlyIfKeyDoesNotExistExpire ( string key , byte [ ] value , int expireInSeconds )
391
- {
392
- if ( key == null )
393
- throw new ArgumentNullException ( "key" ) ;
394
- value = value ?? new byte [ 0 ] ;
395
-
396
- if ( value . Length > OneGb )
397
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
398
-
399
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . SetIfKeyDoesNotExist , Commands . ExpireInSeconds , expireInSeconds . ToUtf8Bytes ( ) ) ;
400
- }
401
-
402
- public void SetExpireInMilliseconds ( string key , byte value , long expireInMs )
403
- {
404
- if ( key == null )
405
- throw new ArgumentNullException ( "key" ) ;
406
- value = value ?? new byte [ 0 ] ;
407
-
408
- if ( value . Length > OneGb )
409
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
410
-
411
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInMilliseconds , expireInMs . ToUtf8Bytes ( ) ) ;
412
- }
413
-
414
- public void SetExpireInSeconds ( string key , byte value , int expireInSeconds )
415
- {
416
- if ( key == null )
417
- throw new ArgumentNullException ( "key" ) ;
418
- value = value ?? new byte [ 0 ] ;
419
-
420
- if ( value . Length > OneGb )
421
- throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
422
-
423
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInSeconds , expireInSeconds . ToUtf8Bytes ( ) ) ;
327
+ if ( ! expirySeconds . HasValue && ! exists . HasValue )
328
+ {
329
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ) ;
330
+ }
331
+ else if ( ! exists . HasValue && expiryMs . HasValue )
332
+ {
333
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInMilliseconds , expiryMs . Value . ToUtf8Bytes ( ) ) ;
334
+ }
335
+ else if ( ! exists . HasValue && expirySeconds . HasValue )
336
+ {
337
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInSeconds , expirySeconds . Value . ToUtf8Bytes ( ) ) ;
338
+ }
339
+ else if ( exists . HasValue && ! expirySeconds . HasValue && ! expiryMs . HasValue )
340
+ {
341
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist ) ;
342
+ }
343
+ else if ( exists . HasValue && expirySeconds . HasValue ) {
344
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist , Commands . ExpireInSeconds , expirySeconds . Value . ToUtf8Bytes ( ) ) ;
345
+ }
346
+ else if ( exists . HasValue && expiryMs . HasValue ) {
347
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist , Commands . ExpireInMilliseconds , expiryMs . Value . ToUtf8Bytes ( ) ) ;
348
+ }
424
349
}
425
350
426
351
public void SetEx ( string key , int expireInSeconds , byte [ ] value )
0 commit comments