@@ -167,6 +167,40 @@ def zpopmin(key, count = nil)
167
167
end
168
168
end
169
169
170
+ # Removes and returns up to count members with scores in the sorted set stored at key.
171
+ #
172
+ # @example Popping a member
173
+ # redis.bzmpop('zset')
174
+ # #=> ['zset', ['a', 1.0]]
175
+ # @example With count option
176
+ # redis.bzmpop('zset', count: 2)
177
+ # #=> ['zset', [['a', 1.0], ['b', 2.0]]
178
+ #
179
+ # @params timeout [Float] a float value specifying the maximum number of seconds to block) elapses.
180
+ # A timeout of zero can be used to block indefinitely.
181
+ # @params key [String, Array<String>] one or more keys with sorted sets
182
+ # @params modifier [String]
183
+ # - when `"MIN"` - the elements popped are those with lowest scores
184
+ # - when `"MAX"` - the elements popped are those with the highest scores
185
+ # @params count [Integer] a number of members to pop
186
+ #
187
+ # @return [Array<String, Array<String, Float>>] list of popped elements and scores
188
+ def bzmpop ( timeout , *keys , modifier : "MIN" , count : nil )
189
+ raise ArgumentError , "Pick either MIN or MAX" unless modifier == "MIN" || modifier == "MAX"
190
+
191
+ args = [ :bzmpop , timeout , keys . size , *keys , modifier ]
192
+ args << "COUNT" << Integer ( count ) if count
193
+
194
+ send_blocking_command ( args , timeout ) do |response |
195
+ response &.map do |entry |
196
+ case entry
197
+ when String then entry
198
+ when Array then entry . map { |pair | FloatifyPairs . call ( pair ) } . flatten ( 1 )
199
+ end
200
+ end
201
+ end
202
+ end
203
+
170
204
# Removes and returns up to count members with scores in the sorted set stored at key.
171
205
#
172
206
# @example Popping a member
@@ -187,11 +221,7 @@ def zmpop(*keys, modifier: "MIN", count: nil)
187
221
raise ArgumentError , "Pick either MIN or MAX" unless modifier == "MIN" || modifier == "MAX"
188
222
189
223
args = [ :zmpop , keys . size , *keys , modifier ]
190
-
191
- if count
192
- args << "COUNT"
193
- args << Integer ( count )
194
- end
224
+ args << "COUNT" << Integer ( count ) if count
195
225
196
226
send_command ( args ) do |response |
197
227
response &.map do |entry |
0 commit comments