@@ -2480,6 +2480,48 @@ func TestStreamOffset(t *testing.T) {
24802480 require .ErrorContains (t , rdb .Do (ctx , "XREVRANGE" , "mystream" ).Err (), "wrong number of arguments" )
24812481 require .ErrorContains (t , rdb .Do (ctx , "XREVRANGE" , "mystream" , "+" ).Err (), "wrong number of arguments" )
24822482 })
2483+
2484+ t .Run ("XPENDING with specific end ID should filter correctly" , func (t * testing.T ) {
2485+ streamKey := "xpending-endid-test"
2486+ group := "grp"
2487+ consumer := "con"
2488+ require .NoError (t , rdb .Del (ctx , streamKey ).Err ())
2489+
2490+ id1 , err := rdb .XAdd (ctx , & redis.XAddArgs {Stream : streamKey , Values : []string {"f" , "1" }}).Result ()
2491+ require .NoError (t , err )
2492+ id2 , err := rdb .XAdd (ctx , & redis.XAddArgs {Stream : streamKey , Values : []string {"f" , "2" }}).Result ()
2493+ require .NoError (t , err )
2494+ id3 , err := rdb .XAdd (ctx , & redis.XAddArgs {Stream : streamKey , Values : []string {"f" , "3" }}).Result ()
2495+ require .NoError (t , err )
2496+
2497+ require .NoError (t , rdb .XGroupCreateMkStream (ctx , streamKey , group , "0" ).Err ())
2498+ // Read all entries so they become pending
2499+ _ , err = rdb .XReadGroup (ctx , & redis.XReadGroupArgs {Group : group , Consumer : consumer , Streams : []string {streamKey , ">" }, Count : 10 }).Result ()
2500+ require .NoError (t , err )
2501+
2502+ // XPENDING extended form: same ID range rules as XRANGE (see Redis docs). Use XPENDING with end_id = id1.
2503+ result , err := rdb .Do (ctx , "XPENDING" , streamKey , group , id1 , id1 , "10" ).Result ()
2504+ require .NoError (t , err )
2505+ entries , ok := result .([]interface {})
2506+ require .True (t , ok )
2507+ require .Len (t , entries , 1 , "XPENDING with end_id=id1 should return only 1 entry" )
2508+
2509+ // Use XPENDING with range [id1, id2] (should return 2 entries).
2510+ result , err = rdb .Do (ctx , "XPENDING" , streamKey , group , id1 , id2 , "10" ).Result ()
2511+ require .NoError (t , err )
2512+ entries , ok = result .([]interface {})
2513+ require .True (t , ok )
2514+ require .Len (t , entries , 2 , "XPENDING with range [id1,id2] should return 2 entries" )
2515+
2516+ // Use XPENDING with range [id1, id3] (should return all 3 entries).
2517+ result , err = rdb .Do (ctx , "XPENDING" , streamKey , group , id1 , id3 , "10" ).Result ()
2518+ require .NoError (t , err )
2519+ entries , ok = result .([]interface {})
2520+ require .True (t , ok )
2521+ require .Len (t , entries , 3 , "XPENDING with range [id1,id3] should return 3 entries" )
2522+
2523+ require .NoError (t , rdb .Del (ctx , streamKey ).Err ())
2524+ })
24832525}
24842526
24852527func parseStreamEntryID (id string ) (ts int64 , seqNum int64 ) {
0 commit comments