@@ -327,7 +327,7 @@ public void Set(string key, byte[] value)
327
327
SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ) ;
328
328
}
329
329
330
- public void Set ( string key , byte [ ] value , int ? expirySeconds = null , long ? expiryMs = null , bool ? exists = null )
330
+ public void Set ( string key , byte [ ] value , int expirySeconds , long expiryMs = 0 , bool ? exists = null )
331
331
{
332
332
if ( key == null )
333
333
throw new ArgumentNullException ( "key" ) ;
@@ -336,29 +336,20 @@ public void Set(string key, byte[] value, int? expirySeconds = null, long? expir
336
336
if ( value . Length > OneGb )
337
337
throw new ArgumentException ( "value exceeds 1G" , "value" ) ;
338
338
339
- if ( ! expirySeconds . HasValue && ! exists . HasValue )
339
+ if ( exists == null )
340
340
{
341
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ) ;
341
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ,
342
+ Commands . Ex , expirySeconds . ToUtf8Bytes ( ) ,
343
+ Commands . Px , expiryMs . ToUtf8Bytes ( ) ) ;
342
344
}
343
- else if ( ! exists . HasValue && expiryMs . HasValue )
344
- {
345
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInMilliseconds , expiryMs . Value . ToUtf8Bytes ( ) ) ;
346
- }
347
- else if ( ! exists . HasValue && expirySeconds . HasValue )
348
- {
349
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , Commands . ExpireInSeconds , expirySeconds . Value . ToUtf8Bytes ( ) ) ;
350
- }
351
- else if ( exists . HasValue && ! expirySeconds . HasValue && ! expiryMs . HasValue )
352
- {
353
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist ) ;
354
- }
355
- else if ( exists . HasValue && expirySeconds . HasValue )
356
- {
357
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist , Commands . ExpireInSeconds , expirySeconds . Value . ToUtf8Bytes ( ) ) ;
358
- }
359
- else if ( exists . HasValue && expiryMs . HasValue )
345
+ else
360
346
{
361
- SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value , exists . Value ? Commands . SetIfKeyExists : Commands . SetIfKeyDoesNotExist , Commands . ExpireInMilliseconds , expiryMs . Value . ToUtf8Bytes ( ) ) ;
347
+ var entryExists = exists . Value ? Commands . Xx : Commands . Nx ;
348
+
349
+ SendExpectSuccess ( Commands . Set , key . ToUtf8Bytes ( ) , value ,
350
+ Commands . Ex , expirySeconds . ToUtf8Bytes ( ) ,
351
+ Commands . Px , expiryMs . ToUtf8Bytes ( ) ,
352
+ entryExists ) ;
362
353
}
363
354
}
364
355
0 commit comments