@@ -2990,13 +2990,31 @@ def xdel(key, *ids)
2990
2990
# redis.xrange('mystream', count: 10)
2991
2991
#
2992
2992
# @param key [String] the stream key
2993
- # @param first [String] first entry id of range, default value is `- `
2994
- # @param last [String] last entry id of range, default value is `+ `
2993
+ # @param start [String] first entry id of range, default value is `+ `
2994
+ # @param end [String] last entry id of range, default value is `- `
2995
2995
# @param count [Integer] the number of entries as limit
2996
2996
#
2997
2997
# @return [Hash{String => Hash}] the entries
2998
- def xrange ( key , first : '-' , last : '+' , count : nil )
2999
- args = [ :xrange , key , first , last ]
2998
+
2999
+ # Fetches entries of the stream in ascending order.
3000
+ #
3001
+ # @example Without options
3002
+ # redis.xrange('mystream')
3003
+ # @example With a specific start
3004
+ # redis.xrange('mystream', '0-1')
3005
+ # @example With a specific start and end
3006
+ # redis.xrange('mystream', '0-1', '0-3')
3007
+ # @example With count options
3008
+ # redis.xrange('mystream', count: 10)
3009
+ #
3010
+ # @param key [String] the stream key
3011
+ # @param start [String] first entry id of range, default value is `-`
3012
+ # @param end [String] last entry id of range, default value is `+`
3013
+ # @param count [Integer] the number of entries as limit
3014
+ #
3015
+ # @return [Array<Array<String, Hash>>] the ids and entries pairs
3016
+ def xrange ( key , start = '-' , _end = '+' , count : nil )
3017
+ args = [ :xrange , key , start , _end ]
3000
3018
args . concat ( [ 'COUNT' , count ] ) if count
3001
3019
synchronize { |client | client . call ( args , &HashifyStreamEntries ) }
3002
3020
end
@@ -3005,21 +3023,21 @@ def xrange(key, first: '-', last: '+', count: nil)
3005
3023
#
3006
3024
# @example Without options
3007
3025
# redis.xrevrange('mystream')
3008
- # @example With first entry id option
3009
- # redis.xrevrange('mystream', first: '0-1 ')
3010
- # @example With first and last entry id options
3011
- # redis.xrevrange('mystream', first: '0-1 ', last: '0-3 ')
3026
+ # @example With a specific end
3027
+ # redis.xrevrange('mystream', '0-3 ')
3028
+ # @example With a specific end and start
3029
+ # redis.xrevrange('mystream', '0-3 ', '0-1 ')
3012
3030
# @example With count options
3013
3031
# redis.xrevrange('mystream', count: 10)
3014
3032
#
3015
- # @param key [String] the stream key
3016
- # @param first [String] first entry id of range, default value is `- `
3017
- # @param last [String] last entry id of range, default value is `+ `
3018
- # @param count [Integer] the number of entries as limit
3033
+ # @param key [String] the stream key
3034
+ # @param end [String] first entry id of range, default value is `+ `
3035
+ # @param start [String] last entry id of range, default value is `- `
3036
+ # @params count [Integer] the number of entries as limit
3019
3037
#
3020
- # @return [Hash{ String => Hash} ] the entries
3021
- def xrevrange ( key , first : '- ', last : '+ ', count : nil )
3022
- args = [ :xrevrange , key , last , first ]
3038
+ # @return [Array<Array< String, Hash>> ] the ids and entries pairs
3039
+ def xrevrange ( key , _end = '+ ', start = '- ', count : nil )
3040
+ args = [ :xrevrange , key , _end , start ]
3023
3041
args . concat ( [ 'COUNT' , count ] ) if count
3024
3042
synchronize { |client | client . call ( args , &HashifyStreamEntries ) }
3025
3043
end
@@ -3055,8 +3073,8 @@ def xlen(key)
3055
3073
# @return [Hash{String => Hash{String => Hash}}] the entries
3056
3074
def xread ( keys , ids , count : nil , block : nil )
3057
3075
args = [ :xread ]
3058
- args . concat ( [ 'COUNT' , count ] ) if count
3059
- args . concat ( [ 'BLOCK' , block . to_i ] ) if block
3076
+ args << 'COUNT' << count if count
3077
+ args << 'BLOCK' << block . to_i if block
3060
3078
_xread ( args , keys , ids , block )
3061
3079
end
3062
3080
@@ -3113,9 +3131,9 @@ def xgroup(subcommand, key, group, id_or_consumer = nil, mkstream: false)
3113
3131
# @return [Hash{String => Hash{String => Hash}}] the entries
3114
3132
def xreadgroup ( group , consumer , keys , ids , opts = { } )
3115
3133
args = [ :xreadgroup , 'GROUP' , group , consumer ]
3116
- args . concat ( [ 'COUNT' , opts [ :count ] ] ) if opts [ :count ]
3117
- args . concat ( [ 'BLOCK' , opts [ :block ] . to_i ] ) if opts [ :block ]
3118
- args << 'NOACK' if opts [ :noack ]
3134
+ args << 'COUNT' << opts [ :count ] if opts [ :count ]
3135
+ args << 'BLOCK' << opts [ :block ] . to_i if opts [ :block ]
3136
+ args << 'NOACK' if opts [ :noack ]
3119
3137
_xread ( args , keys , ids , opts [ :block ] )
3120
3138
end
3121
3139
@@ -3186,26 +3204,31 @@ def xclaim(key, group, consumer, min_idle_time, *ids, **opts)
3186
3204
# @example With key and group
3187
3205
# redis.xpending('mystream', 'mygroup')
3188
3206
# @example With range options
3189
- # redis.xpending('mystream', 'mygroup', first: '-', last: '+', count: 10)
3207
+ # redis.xpending('mystream', 'mygroup', '-', '+', 10)
3190
3208
# @example With range and consumer options
3191
- # redis.xpending('mystream', 'mygroup', 'consumer1', first: ' -', last: '+', count: 10 )
3209
+ # redis.xpending('mystream', 'mygroup', '-', '+', 10, 'consumer1' )
3192
3210
#
3193
- # @param key [String] the stream key
3194
- # @param group [String] the consumer group name
3195
- # @param consumer [String] the consumer name
3196
- # @param opts [Hash] several options for `XPENDING` command
3197
- #
3198
- # @option opts [String] :first first entry id of range
3199
- # @option opts [String] :last last entry id of range
3200
- # @option opts [Integer] :count the number of entries as limit
3211
+ # @param key [String] the stream key
3212
+ # @param group [String] the consumer group name
3213
+ # @param start [String] start first entry id of range
3214
+ # @param end [String] end last entry id of range
3215
+ # @param count [Integer] count the number of entries as limit
3216
+ # @param consumer [String] the consumer name
3201
3217
#
3202
3218
# @return [Hash] the summary of pending entries
3203
3219
# @return [Array<Hash>] the pending entries details if options were specified
3204
- def xpending ( key , group , consumer = nil , **opts )
3205
- args = [ :xpending , key , group , opts [ :first ] , opts [ :last ] , opts [ :count ] , consumer ] . compact
3206
- summary_needed = consumer . nil? && opts . empty?
3220
+ def xpending ( key , group , *args )
3221
+ command_args = [ :xpending , key , group ]
3222
+ case args . size
3223
+ when 0 , 3 , 4
3224
+ command_args . concat ( args )
3225
+ else
3226
+ raise ArgumentError , "wrong number of arguments (given #{ args . size + 2 } , expected 2, 5 or 6)"
3227
+ end
3228
+
3229
+ summary_needed = args . empty?
3207
3230
blk = summary_needed ? HashifyStreamPendings : HashifyStreamPendingDetails
3208
- synchronize { |client | client . call ( args , &blk ) }
3231
+ synchronize { |client | client . call ( command_args , &blk ) }
3209
3232
end
3210
3233
3211
3234
# Interact with the sentinel command (masters, master, slaves, failover)
@@ -3365,7 +3388,7 @@ def method_missing(command, *args)
3365
3388
lambda { |reply |
3366
3389
reply . map do |entry_id , values |
3367
3390
[ entry_id , values . each_slice ( 2 ) . to_h ]
3368
- end . to_h
3391
+ end
3369
3392
}
3370
3393
3371
3394
HashifyStreamPendings =
@@ -3459,7 +3482,9 @@ def _subscription(method, timeout, channels, block)
3459
3482
def _xread ( args , keys , ids , blocking_timeout_msec )
3460
3483
keys = keys . is_a? ( Array ) ? keys : [ keys ]
3461
3484
ids = ids . is_a? ( Array ) ? ids : [ ids ]
3462
- args . concat ( [ 'STREAMS' ] , keys , ids )
3485
+ args << 'STREAMS'
3486
+ args . concat ( keys )
3487
+ args . concat ( ids )
3463
3488
3464
3489
synchronize do |client |
3465
3490
if blocking_timeout_msec . nil?
0 commit comments