lib/redis.rb in redis-3.0.7 vs lib/redis.rb in redis-3.1.0
- old
+ new
@@ -904,10 +904,31 @@
synchronize do |client|
client.call([:bitop, operation, destkey] + keys)
end
end
+ # Return the position of the first bit set to 1 or 0 in a string.
+ #
+ # @param [String] key
+ # @param [Fixnum] bit whether to look for the first 1 or 0 bit
+ # @param [Fixnum] start start index
+ # @param [Fixnum] stop stop index
+ # @return [Fixnum] the position of the first 1/0 bit.
+ # -1 if looking for 1 and it is not found or start and stop are given.
+ def bitpos(key, bit, start=nil, stop=nil)
+ if stop and not start
+ raise(ArgumentError, 'stop parameter specified without start parameter')
+ end
+
+ synchronize do |client|
+ command = [:bitpos, key, bit]
+ command << start if start
+ command << stop if stop
+ client.call(command)
+ end
+ end
+
# Set the string value of a key and return its old value.
#
# @param [String] key
# @param [String] value value to replace the current value with
# @return [String] the old value stored in the key, or `nil` if the key
@@ -2410,9 +2431,42 @@
cursor = 0
loop do
cursor, keys = sscan(key, cursor, options)
keys.each(&block)
break if cursor == "0"
+ end
+ end
+
+ # Add one or more members to a HyperLogLog structure.
+ #
+ # @param [String] key
+ # @param [String, Array<String>] member one member, or array of members
+ # @return [Boolean] true if at least 1 HyperLogLog internal register was altered. false otherwise.
+ def pfadd(key, member)
+ synchronize do |client|
+ client.call([:pfadd, key, member], &_boolify)
+ end
+ end
+
+ # Get the approximate cardinality of members added to HyperLogLog structure.
+ #
+ # @param [String] key
+ # @return [Fixnum]
+ def pfcount(key)
+ synchronize do |client|
+ client.call([:pfcount, key])
+ end
+ end
+
+ # Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of
+ # the observed Sets of the source HyperLogLog structures.
+ #
+ # @param [String] dest_key destination key
+ # @param [String, Array<String>] source_key source key, or array of keys
+ # @return [Boolean]
+ def pfmerge(dest_key, *source_key)
+ synchronize do |client|
+ client.call([:pfmerge, dest_key, *source_key], &_boolify_set)
end
end
def id
@original_client.id