@@ -316,6 +316,12 @@ def parse_xclaim(response, **options):
316
316
return parse_stream_list (response )
317
317
318
318
319
+ def parse_xautoclaim (response , ** options ):
320
+ if options .get ('parse_justid' , False ):
321
+ return response [1 ]
322
+ return parse_stream_list (response [1 ])
323
+
324
+
319
325
def parse_xinfo_stream (response ):
320
326
data = pairs_to_dict (response , decode_keys = True )
321
327
first = data ['first-entry' ]
@@ -684,6 +690,7 @@ class Redis:
684
690
'SSCAN' : parse_scan ,
685
691
'TIME' : lambda x : (int (x [0 ]), int (x [1 ])),
686
692
'XCLAIM' : parse_xclaim ,
693
+ 'XAUTOCLAIM' : parse_xautoclaim ,
687
694
'XGROUP CREATE' : bool_ok ,
688
695
'XGROUP DELCONSUMER' : int ,
689
696
'XGROUP DESTROY' : bool ,
@@ -2601,6 +2608,46 @@ def xadd(self, name, fields, id='*', maxlen=None, approximate=True,
2601
2608
pieces .extend (pair )
2602
2609
return self .execute_command ('XADD' , name , * pieces )
2603
2610
2611
+ def xautoclaim (self , name , groupname , consumername , min_idle_time ,
2612
+ start_id = 0 , count = None , justid = False ):
2613
+ """
2614
+ Transfers ownership of pending stream entries that match the specified
2615
+ criteria. Conceptually, equivalent to calling XPENDING and then XCLAIM,
2616
+ but provides a more straightforward way to deal with message delivery
2617
+ failures via SCAN-like semantics.
2618
+ name: name of the stream.
2619
+ groupname: name of the consumer group.
2620
+ consumername: name of a consumer that claims the message.
2621
+ min_idle_time: filter messages that were idle less than this amount of
2622
+ milliseconds.
2623
+ start_id: filter messages with equal or greater ID.
2624
+ count: optional integer, upper limit of the number of entries that the
2625
+ command attempts to claim. Set to 100 by default.
2626
+ justid: optional boolean, false by default. Return just an array of IDs
2627
+ of messages successfully claimed, without returning the actual message
2628
+ """
2629
+ try :
2630
+ if int (min_idle_time ) < 0 :
2631
+ raise DataError ("XAUTOCLAIM min_idle_time must be a non"
2632
+ "negative integer" )
2633
+ except TypeError :
2634
+ pass
2635
+
2636
+ kwargs = {}
2637
+ pieces = [name , groupname , consumername , min_idle_time , start_id ]
2638
+
2639
+ try :
2640
+ if int (count ) < 0 :
2641
+ raise DataError ("XPENDING count must be a integer >= 0" )
2642
+ pieces .extend ([b'COUNT' , count ])
2643
+ except TypeError :
2644
+ pass
2645
+ if justid :
2646
+ pieces .append (b'JUSTID' )
2647
+ kwargs ['parse_justid' ] = True
2648
+
2649
+ return self .execute_command ('XAUTOCLAIM' , * pieces , ** kwargs )
2650
+
2604
2651
def xclaim (self , name , groupname , consumername , min_idle_time , message_ids ,
2605
2652
idle = None , time = None , retrycount = None , force = False ,
2606
2653
justid = False ):
0 commit comments