@@ -1156,7 +1156,7 @@ def rpoplpush(source, destination)
11561156 end
11571157 end
11581158
1159- def _bpop ( cmd , args )
1159+ def _bpop ( cmd , args , & blk )
11601160 options = { }
11611161
11621162 case args . last
@@ -1177,7 +1177,7 @@ def _bpop(cmd, args)
11771177 synchronize do |client |
11781178 command = [ cmd , keys , timeout ]
11791179 timeout += client . timeout if timeout > 0
1180- client . call_with_timeout ( command , timeout )
1180+ client . call_with_timeout ( command , timeout , & blk )
11811181 end
11821182 end
11831183
@@ -1628,6 +1628,90 @@ def zrem(key, member)
16281628 end
16291629 end
16301630
1631+ # Removes and returns up to count members with the highest scores in the sorted set stored at key.
1632+ #
1633+ # @example Popping a member
1634+ # redis.zpopmax('zset')
1635+ # #=> ['b', 2.0]
1636+ # @example With count option
1637+ # redis.zpopmax('zset', 2)
1638+ # #=> [['b', 2.0], ['a', 1.0]]
1639+ #
1640+ # @params key [String] a key of the sorted set
1641+ # @params count [Integer] a number of members
1642+ #
1643+ # @return [Array<String, Float>] element and score pair if count is not specified
1644+ # @return [Array<Array<String, Float>>] list of popped elements and scores
1645+ def zpopmax ( key , count = nil )
1646+ synchronize do |client |
1647+ members = client . call ( [ :zpopmax , key , count ] . compact , &FloatifyPairs )
1648+ count . to_i > 1 ? members : members . first
1649+ end
1650+ end
1651+
1652+ # Removes and returns up to count members with the lowest scores in the sorted set stored at key.
1653+ #
1654+ # @example Popping a member
1655+ # redis.zpopmin('zset')
1656+ # #=> ['a', 1.0]
1657+ # @example With count option
1658+ # redis.zpopmin('zset', 2)
1659+ # #=> [['a', 1.0], ['b', 2.0]]
1660+ #
1661+ # @params key [String] a key of the sorted set
1662+ # @params count [Integer] a number of members
1663+ #
1664+ # @return [Array<String, Float>] element and score pair if count is not specified
1665+ # @return [Array<Array<String, Float>>] list of popped elements and scores
1666+ def zpopmin ( key , count = nil )
1667+ synchronize do |client |
1668+ members = client . call ( [ :zpopmin , key , count ] . compact , &FloatifyPairs )
1669+ count . to_i > 1 ? members : members . first
1670+ end
1671+ end
1672+
1673+ # Removes and returns up to count members with the highest scores in the sorted set stored at keys,
1674+ # or block until one is available.
1675+ #
1676+ # @example Popping a member from a sorted set
1677+ # redis.bzpopmax('zset', 1)
1678+ # #=> ['zset', 'b', 2.0]
1679+ # @example Popping a member from multiple sorted sets
1680+ # redis.bzpopmax('zset1', 'zset2', 1)
1681+ # #=> ['zset1', 'b', 2.0]
1682+ #
1683+ # @params keys [Array<String>] one or multiple keys of the sorted sets
1684+ # @params timeout [Integer] the maximum number of seconds to block
1685+ #
1686+ # @return [Array<String, String, Float>] a touple of key, member and score
1687+ # @return [nil] when no element could be popped and the timeout expired
1688+ def bzpopmax ( *args )
1689+ _bpop ( :bzpopmax , args ) do |reply |
1690+ reply . is_a? ( Array ) ? [ reply [ 0 ] , reply [ 1 ] , Floatify . call ( reply [ 2 ] ) ] : reply
1691+ end
1692+ end
1693+
1694+ # Removes and returns up to count members with the lowest scores in the sorted set stored at keys,
1695+ # or block until one is available.
1696+ #
1697+ # @example Popping a member from a sorted set
1698+ # redis.bzpopmin('zset', 1)
1699+ # #=> ['zset', 'a', 1.0]
1700+ # @example Popping a member from multiple sorted sets
1701+ # redis.bzpopmin('zset1', 'zset2', 1)
1702+ # #=> ['zset1', 'a', 1.0]
1703+ #
1704+ # @params keys [Array<String>] one or multiple keys of the sorted sets
1705+ # @params timeout [Integer] the maximum number of seconds to block
1706+ #
1707+ # @return [Array<String, String, Float>] a touple of key, member and score
1708+ # @return [nil] when no element could be popped and the timeout expired
1709+ def bzpopmin ( *args )
1710+ _bpop ( :bzpopmin , args ) do |reply |
1711+ reply . is_a? ( Array ) ? [ reply [ 0 ] , reply [ 1 ] , Floatify . call ( reply [ 2 ] ) ] : reply
1712+ end
1713+ end
1714+
16311715 # Get the score associated with the given member in a sorted set.
16321716 #
16331717 # @example Get the score for member "a"
0 commit comments