@@ -3474,5 +3474,180 @@ public void TestConstantExpressionContains()
34743474 _ = collection . Where ( lambada ) . ToList ( ) ;
34753475 _substitute . Received ( ) . Execute ( "FT.SEARCH" , "person-idx" , "(@TagField:{James|Bond})" , "LIMIT" , "0" , "100" ) ;
34763476 }
3477+
3478+ [ Fact ]
3479+ public async Task EnumerateAllWhenKeyExpires ( )
3480+ {
3481+ RedisReply firstReply = new RedisReply [ ]
3482+ {
3483+ new ( 2 ) ,
3484+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:E912BED67BD64386B4FDC7322D" ) ,
3485+ new ( new RedisReply [ ]
3486+ {
3487+ "$" ,
3488+ "{\" Name\" :\" Steve\" ,\" Age\" :32,\" Height\" :71.0, \" Id\" :\" E912BED67BD64386B4FDC7322D\" }"
3489+ } ) ,
3490+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:01FVN836BNQGYMT80V7RCVY73N" ) ,
3491+ // Key expired while executing the search
3492+ new ( Array . Empty < RedisReply > ( ) )
3493+ } ;
3494+ RedisReply secondReply = new RedisReply [ ]
3495+ {
3496+ new ( 2 ) ,
3497+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:4F6AE0A9BAE044E4B2D2186044" ) ,
3498+ new ( new RedisReply [ ]
3499+ {
3500+ "$" ,
3501+ "{\" Name\" :\" Josh\" ,\" Age\" :30,\" Height\" :12.0, \" Id\" :\" 4F6AE0A9BAE044E4B2D2186044\" }"
3502+ } )
3503+ } ;
3504+ RedisReply finalEmptyResult = new RedisReply [ ]
3505+ {
3506+ new ( 0 ) ,
3507+ } ;
3508+
3509+ _substitute . ClearSubstitute ( ) ;
3510+ _substitute . ExecuteAsync (
3511+ "FT.SEARCH" ,
3512+ "person-idx" ,
3513+ "*" ,
3514+ "LIMIT" ,
3515+ "0" ,
3516+ "2" ) . Returns ( firstReply ) ;
3517+ _substitute . ExecuteAsync (
3518+ "FT.SEARCH" ,
3519+ "person-idx" ,
3520+ "*" ,
3521+ "LIMIT" ,
3522+ "2" ,
3523+ "2" ) . Returns ( secondReply ) ;
3524+ _substitute . ExecuteAsync (
3525+ "FT.SEARCH" ,
3526+ "person-idx" ,
3527+ "*" ,
3528+ "LIMIT" ,
3529+ "4" ,
3530+ "2" ) . Returns ( finalEmptyResult ) ;
3531+
3532+ var people = new List < Person > ( ) ;
3533+ // Chunk size 2 induces the iterator to call FT.SEARCH 3 times
3534+ await foreach ( var person in new RedisCollection < Person > ( _substitute , 2 ) )
3535+ {
3536+ people . Add ( person ) ;
3537+ }
3538+
3539+ Assert . Equal ( 2 , people . Count ) ;
3540+
3541+ Assert . Equal ( "Steve" , people [ 0 ] . Name ) ;
3542+ Assert . Equal ( "Josh" , people [ 1 ] . Name ) ;
3543+ }
3544+
3545+ [ Fact ]
3546+ public async Task EnumerateAllWhenKeyExpiresAtEnd ( )
3547+ {
3548+ RedisReply firstReply = new RedisReply [ ]
3549+ {
3550+ new ( 2 ) ,
3551+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:E912BED67BD64386B4FDC7322D" ) ,
3552+ new ( new RedisReply [ ]
3553+ {
3554+ "$" ,
3555+ "{\" Name\" :\" Steve\" ,\" Age\" :32,\" Height\" :71.0, \" Id\" :\" E912BED67BD64386B4FDC7322D\" }"
3556+ } ) ,
3557+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:4F6AE0A9BAE044E4B2D2186044" ) ,
3558+ new ( new RedisReply [ ]
3559+ {
3560+ "$" ,
3561+ "{\" Name\" :\" Josh\" ,\" Age\" :30,\" Height\" :12.0, \" Id\" :\" 4F6AE0A9BAE044E4B2D2186044\" }"
3562+ } )
3563+ } ;
3564+ RedisReply secondReply = new RedisReply [ ]
3565+ {
3566+ new ( 1 ) ,
3567+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:01FVN836BNQGYMT80V7RCVY73N" ) ,
3568+ // Key expired while executing the search
3569+ new ( Array . Empty < RedisReply > ( ) )
3570+ } ;
3571+ RedisReply finalEmptyResult = new RedisReply [ ]
3572+ {
3573+ new ( 0 ) ,
3574+ } ;
3575+
3576+ _substitute . ClearSubstitute ( ) ;
3577+ _substitute . ExecuteAsync (
3578+ "FT.SEARCH" ,
3579+ "person-idx" ,
3580+ "*" ,
3581+ "LIMIT" ,
3582+ "0" ,
3583+ "2" ) . Returns ( firstReply ) ;
3584+ _substitute . ExecuteAsync (
3585+ "FT.SEARCH" ,
3586+ "person-idx" ,
3587+ "*" ,
3588+ "LIMIT" ,
3589+ "2" ,
3590+ "2" ) . Returns ( secondReply ) ;
3591+ _substitute . ExecuteAsync (
3592+ "FT.SEARCH" ,
3593+ "person-idx" ,
3594+ "*" ,
3595+ "LIMIT" ,
3596+ "4" ,
3597+ "2" ) . Returns ( finalEmptyResult ) ;
3598+
3599+ var people = new List < Person > ( ) ;
3600+ // Chunk size 2 induces the iterator to call FT.SEARCH 3 times
3601+ await foreach ( var person in new RedisCollection < Person > ( _substitute , 2 ) )
3602+ {
3603+ people . Add ( person ) ;
3604+ }
3605+
3606+ Assert . Equal ( 2 , people . Count ) ;
3607+
3608+ Assert . Equal ( "Steve" , people [ 0 ] . Name ) ;
3609+ Assert . Equal ( "Josh" , people [ 1 ] . Name ) ;
3610+ }
3611+
3612+ [ Fact ]
3613+ public async Task EnumerateAllButAllExpired ( )
3614+ {
3615+ RedisReply firstReply = new RedisReply [ ]
3616+ {
3617+ new ( 1 ) ,
3618+ new ( "Redis.OM.Unit.Tests.RediSearchTests.Person:01FVN836BNQGYMT80V7RCVY73N" ) ,
3619+ // Key expired while executing the search
3620+ new ( Array . Empty < RedisReply > ( ) )
3621+ } ;
3622+ RedisReply finalEmptyResult = new RedisReply [ ]
3623+ {
3624+ new ( 0 ) ,
3625+ } ;
3626+
3627+ _substitute . ClearSubstitute ( ) ;
3628+ _substitute . ExecuteAsync (
3629+ "FT.SEARCH" ,
3630+ "person-idx" ,
3631+ "*" ,
3632+ "LIMIT" ,
3633+ "0" ,
3634+ "2" ) . Returns ( firstReply ) ;
3635+ _substitute . ExecuteAsync (
3636+ "FT.SEARCH" ,
3637+ "person-idx" ,
3638+ "*" ,
3639+ "LIMIT" ,
3640+ "4" ,
3641+ "2" ) . Returns ( finalEmptyResult ) ;
3642+
3643+ var people = new List < Person > ( ) ;
3644+ // Chunk size 2 induces the iterator to call FT.SEARCH twice
3645+ await foreach ( var person in new RedisCollection < Person > ( _substitute , 2 ) )
3646+ {
3647+ people . Add ( person ) ;
3648+ }
3649+
3650+ Assert . Empty ( people ) ;
3651+ }
34773652 }
34783653}
0 commit comments