@@ -278,7 +278,8 @@ private unsafe bool ListPopMultiple<TGarnetApi>(ref TGarnetApi storageApi)
278
278
return true ;
279
279
}
280
280
281
- private bool ListBlockingPop ( RespCommand command )
281
+ private bool ListBlockingPop < TGarnetApi > ( RespCommand command , ref TGarnetApi storageApi )
282
+ where TGarnetApi : IGarnetApi
282
283
{
283
284
if ( parseState . Count < 2 )
284
285
{
@@ -289,14 +290,24 @@ private bool ListBlockingPop(RespCommand command)
289
290
290
291
for ( var i = 0 ; i < keysBytes . Length ; i ++ )
291
292
{
292
- keysBytes [ i ] = parseState . GetArgSliceByRef ( i ) . SpanByte . ToByteArray ( ) ;
293
+ var key = parseState . GetArgSliceByRef ( i ) ;
294
+ var status = storageApi . GetKeyType ( key , out var typeName ) ;
295
+ if ( status == GarnetStatus . OK && typeName != CmdStrings . listTyprStr )
296
+ {
297
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_WRONG_TYPE ) ;
298
+ }
299
+
300
+ keysBytes [ i ] = key . SpanByte . ToByteArray ( ) ;
293
301
}
294
302
295
303
if ( ! parseState . TryGetDouble ( parseState . Count - 1 , out var timeout ) )
296
304
{
297
- while ( ! RespWriteUtils . TryWriteError ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT , ref dcurr , dend ) )
298
- SendAndReset ( ) ;
299
- return true ;
305
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT ) ;
306
+ }
307
+
308
+ if ( timeout < 0 )
309
+ {
310
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_IS_NEGATIVE ) ;
300
311
}
301
312
302
313
if ( storeWrapper . itemBroker == null )
@@ -331,7 +342,8 @@ private bool ListBlockingPop(RespCommand command)
331
342
return true ;
332
343
}
333
344
334
- private unsafe bool ListBlockingMove ( )
345
+ private unsafe bool ListBlockingMove < TGarnetApi > ( ref TGarnetApi storageApi )
346
+ where TGarnetApi : IGarnetApi
335
347
{
336
348
if ( parseState . Count != 5 )
337
349
{
@@ -345,19 +357,23 @@ private unsafe bool ListBlockingMove()
345
357
346
358
if ( ! parseState . TryGetDouble ( 4 , out var timeout ) )
347
359
{
348
- while ( ! RespWriteUtils . TryWriteError ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT , ref dcurr , dend ) )
349
- SendAndReset ( ) ;
350
- return true ;
360
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT ) ;
361
+ }
362
+
363
+ if ( timeout < 0 )
364
+ {
365
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_IS_NEGATIVE ) ;
351
366
}
352
367
353
- return ListBlockingMove ( srcKey , dstKey , srcDir , dstDir , timeout ) ;
368
+ return ListBlockingMove ( ref storageApi , srcKey , dstKey , srcDir , dstDir , timeout ) ;
354
369
}
355
370
356
371
/// <summary>
357
372
/// BRPOPLPUSH
358
373
/// </summary>
359
374
/// <returns></returns>
360
- private bool ListBlockingPopPush ( )
375
+ private bool ListBlockingPopPush < TGarnetApi > ( ref TGarnetApi storageApi )
376
+ where TGarnetApi : IGarnetApi
361
377
{
362
378
if ( parseState . Count != 3 )
363
379
{
@@ -371,15 +387,20 @@ private bool ListBlockingPopPush()
371
387
372
388
if ( ! parseState . TryGetDouble ( 2 , out var timeout ) )
373
389
{
374
- while ( ! RespWriteUtils . TryWriteError ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT , ref dcurr , dend ) )
375
- SendAndReset ( ) ;
376
- return true ;
390
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT ) ;
391
+ }
392
+
393
+ if ( timeout < 0 )
394
+ {
395
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_IS_NEGATIVE ) ;
377
396
}
378
397
379
- return ListBlockingMove ( srcKey , dstKey , rightOption , leftOption , timeout ) ;
398
+ return ListBlockingMove ( ref storageApi , srcKey , dstKey , rightOption , leftOption , timeout ) ;
380
399
}
381
400
382
- private bool ListBlockingMove ( ArgSlice srcKey , ArgSlice dstKey , ArgSlice srcDir , ArgSlice dstDir , double timeout )
401
+ private bool ListBlockingMove < TGarnetApi > ( ref TGarnetApi storageApi , ArgSlice srcKey , ArgSlice dstKey ,
402
+ ArgSlice srcDir , ArgSlice dstDir , double timeout )
403
+ where TGarnetApi : IGarnetApi
383
404
{
384
405
var cmdArgs = new ArgSlice [ ] { default , default , default } ;
385
406
@@ -394,14 +415,26 @@ private bool ListBlockingMove(ArgSlice srcKey, ArgSlice dstKey, ArgSlice srcDir,
394
415
return AbortWithErrorMessage ( CmdStrings . RESP_ERR_GENERIC_SYNTAX_ERROR ) ;
395
416
}
396
417
418
+ if ( storeWrapper . itemBroker == null )
419
+ throw new GarnetException ( "Object store is disabled" ) ;
420
+
421
+ if ( storageApi . GetKeyType ( srcKey , out var keyType ) == GarnetStatus . OK &&
422
+ keyType != CmdStrings . listTyprStr )
423
+ {
424
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_WRONG_TYPE ) ;
425
+ }
426
+
427
+ if ( storageApi . GetKeyType ( dstKey , out keyType ) == GarnetStatus . OK &&
428
+ keyType != CmdStrings . listTyprStr )
429
+ {
430
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_WRONG_TYPE ) ;
431
+ }
432
+
397
433
var pSrcDir = ( byte * ) & sourceDirection ;
398
434
var pDstDir = ( byte * ) & destinationDirection ;
399
435
cmdArgs [ 1 ] = new ArgSlice ( pSrcDir , 1 ) ;
400
436
cmdArgs [ 2 ] = new ArgSlice ( pDstDir , 1 ) ;
401
437
402
- if ( storeWrapper . itemBroker == null )
403
- throw new GarnetException ( "Object store is disabled" ) ;
404
-
405
438
var result = storeWrapper . itemBroker . MoveCollectionItemAsync ( RespCommand . BLMOVE , srcKey . ToArray ( ) , this , timeout ,
406
439
cmdArgs ) . Result ;
407
440
@@ -910,7 +943,8 @@ public bool ListSet<TGarnetApi>(ref TGarnetApi storageApi)
910
943
/// BLMPOP timeout numkeys key [key ...] LEFT|RIGHT [COUNT count]
911
944
/// </summary>
912
945
/// <returns></returns>
913
- private unsafe bool ListBlockingPopMultiple ( )
946
+ private unsafe bool ListBlockingPopMultiple < TGarnetApi > ( ref TGarnetApi storageApi )
947
+ where TGarnetApi : IGarnetApi
914
948
{
915
949
if ( parseState . Count < 4 )
916
950
{
@@ -925,6 +959,11 @@ private unsafe bool ListBlockingPopMultiple()
925
959
return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_NOT_VALID_FLOAT ) ;
926
960
}
927
961
962
+ if ( timeout < 0 )
963
+ {
964
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_TIMEOUT_IS_NEGATIVE ) ;
965
+ }
966
+
928
967
// Read count of keys
929
968
if ( ! parseState . TryGetInt ( currTokenId ++ , out var numKeys ) )
930
969
{
@@ -941,7 +980,14 @@ private unsafe bool ListBlockingPopMultiple()
941
980
var keysBytes = new byte [ numKeys ] [ ] ;
942
981
for ( var i = 0 ; i < keysBytes . Length ; i ++ )
943
982
{
944
- keysBytes [ i ] = parseState . GetArgSliceByRef ( currTokenId ++ ) . SpanByte . ToByteArray ( ) ;
983
+ var key = parseState . GetArgSliceByRef ( currTokenId ++ ) ;
984
+ var status = storageApi . GetKeyType ( key , out var typeName ) ;
985
+ if ( status == GarnetStatus . OK && typeName != CmdStrings . listTyprStr )
986
+ {
987
+ return AbortWithErrorMessage ( CmdStrings . RESP_ERR_WRONG_TYPE ) ;
988
+ }
989
+
990
+ keysBytes [ i ] = key . SpanByte . ToByteArray ( ) ;
945
991
}
946
992
947
993
var cmdArgs = new ArgSlice [ 2 ] ;
0 commit comments