@@ -457,12 +457,12 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
457
457
dstKey = cmdArgs [ 0 ] ;
458
458
}
459
459
460
+ var asKey = storageSession . scratchBufferManager . CreateArgSlice ( key ) ;
460
461
// Create a transaction if not currently in a running transaction
461
462
if ( storageSession . txnManager . state != TxnState . Running )
462
463
{
463
464
Debug . Assert ( storageSession . txnManager . state == TxnState . None ) ;
464
465
createTransaction = true ;
465
- var asKey = storageSession. scratchBufferManager . CreateArgSlice ( key ) ;
466
466
if ( initial )
467
467
storageSession. txnManager . SaveKeyEntryToLock ( asKey , false , LockType . Exclusive ) ;
468
468
storageSession. txnManager . SaveKeyEntryToLock ( asKey , true , LockType . Exclusive ) ;
@@ -477,6 +477,7 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
477
477
_ = storageSession. txnManager . Run ( true ) ;
478
478
}
479
479
480
+ var lockableContext = storageSession. txnManager . LockableContext ;
480
481
var objectLockableContext = storageSession . txnManager . ObjectStoreLockableContext ;
481
482
IGarnetObject dstObj = null ;
482
483
byte [ ] arrDstKey = default ;
@@ -490,10 +491,7 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
490
491
if ( ! initial )
491
492
return false;
492
493
493
- var context = storageSession . txnManager . LockableContext ;
494
-
495
- var keySlice = storageSession . scratchBufferManager . CreateArgSlice ( key ) ;
496
- statusOp = storageSession . GET ( keySlice , out ArgSlice _ , ref context ) ;
494
+ statusOp = storageSession . GET ( asKey , out ArgSlice _ , ref lockableContext ) ;
497
495
498
496
if ( statusOp != GarnetStatus . NOTFOUND )
499
497
{
@@ -511,7 +509,7 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
511
509
return true;
512
510
}
513
511
514
- dstStatusOp = storageSession . GET ( dstKey , out ArgSlice _ , ref context ) ;
512
+ dstStatusOp = storageSession . GET ( dstKey , out ArgSlice _ , ref lockableContext ) ;
515
513
if ( dstStatusOp != GarnetStatus . NOTFOUND )
516
514
{
517
515
result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
@@ -543,13 +541,14 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
543
541
if ( currCount == 0 )
544
542
return false;
545
543
544
+ var isSuccessful = false;
546
545
switch ( command )
547
546
{
548
547
case RespCommand. BLPOP :
549
548
case RespCommand. BRPOP :
550
- var isSuccessful = TryGetNextListItem ( listObj , command , out var nextItem ) ;
549
+ isSuccessful = TryGetNextListItem ( listObj , command , out var nextItem ) ;
551
550
result = new CollectionItemResult ( key , nextItem ) ;
552
- return isSuccessful ;
551
+ break ;
553
552
case RespCommand. BLMOVE :
554
553
ListObject dstList;
555
554
var newObj = false ;
@@ -577,8 +576,7 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
577
576
isSuccessful = storageSession . SET ( arrDstKey , dstList , ref objectLockableContext ) ==
578
577
GarnetStatus . OK ;
579
578
}
580
-
581
- return isSuccessful ;
579
+ break;
582
580
case RespCommand. BLMPOP :
583
581
var popDirection = ( OperationDirection ) cmdArgs[ 0 ] . ReadOnlySpan [ 0 ] ;
584
582
var popCount = * ( int * ) ( cmdArgs [ 1 ] . ptr ) ;
@@ -592,11 +590,19 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
592
590
}
593
591
594
592
result = new CollectionItemResult ( key , items ) ;
595
- return true;
593
+ isSuccessful = true ;
594
+ break ;
596
595
default :
597
596
result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
598
597
return initial ;
599
598
}
599
+
600
+ if ( isSuccessful && listObj . LnkList . Count == 0 )
601
+ {
602
+ _ = storageSession . EXPIRE ( asKey , TimeSpan . Zero , out _ , StoreType . Object , ExpireOption . None ,
603
+ ref lockableContext , ref objectLockableContext ) ;
604
+ }
605
+ return isSuccessful ;
600
606
case SortedSetObject setObj:
601
607
currCount = setObj. Count( ) ;
602
608
if ( objectType ! = GarnetObjectType . SortedSet )
@@ -607,8 +613,13 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
607
613
if ( currCount == 0 )
608
614
return false ;
609
615
610
- return TryGetNextSetObjects( key , setObj , currCount , command , cmdArgs , out result ) ;
611
-
616
+ isSuccessful = TryGetNextSetObjects( key , setObj , currCount , command , cmdArgs , out result ) ;
617
+ if ( isSuccessful && setObj . Count ( ) == 0 )
618
+ {
619
+ _ = storageSession . EXPIRE ( asKey , TimeSpan . Zero , out _ , StoreType . Object , ExpireOption . None ,
620
+ ref lockableContext , ref objectLockableContext ) ;
621
+ }
622
+ return isSuccessful;
612
623
default :
613
624
result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
614
625
return initial ;
0 commit comments