lib/redis.rb in redis-4.2.5 vs lib/redis.rb in redis-4.3.0
- old
+ new
@@ -37,10 +37,11 @@
# @option options [String] :host ("127.0.0.1") server hostname
# @option options [Integer] :port (6379) server port
# @option options [String] :path path to server socket (overrides host and port)
# @option options [Float] :timeout (5.0) timeout in seconds
# @option options [Float] :connect_timeout (same as timeout) timeout for initial connect in seconds
+ # @option options [String] :username Username to authenticate against server
# @option options [String] :password Password to authenticate against server
# @option options [Integer] :db (0) Database to select after initial connect
# @option options [Symbol] :driver Driver to use, currently supported: `:ruby`, `:hiredis`, `:synchrony`
# @option options [String] :id ID for the client connection, assigns name to current connection by sending
# `CLIENT SETNAME`
@@ -141,16 +142,17 @@
@client
end
# Authenticate to the server.
#
- # @param [String] password must match the password specified in the
- # `requirepass` directive in the configuration file
+ # @param [Array<String>] args includes both username and password
+ # or only password
# @return [String] `OK`
- def auth(password)
+ # @see https://redis.io/commands/auth AUTH command
+ def auth(*args)
synchronize do |client|
- client.call([:auth, password])
+ client.call([:auth, *args])
end
end
# Change the selected database for the current connection.
#
@@ -2634,16 +2636,17 @@
# @see #eval
def evalsha(*args)
_eval(:evalsha, args)
end
- def _scan(command, cursor, args, match: nil, count: nil, &block)
+ def _scan(command, cursor, args, match: nil, count: nil, type: nil, &block)
# SSCAN/ZSCAN/HSCAN already prepend the key to +args+.
args << cursor
args << "MATCH" << match if match
args << "COUNT" << count if count
+ args << "TYPE" << type if type
synchronize do |client|
client.call([command] + args, &block)
end
end
@@ -2654,15 +2657,19 @@
# redis.scan(0)
# # => ["4", ["key:21", "key:47", "key:42"]]
# @example Retrieve a batch of keys matching a pattern
# redis.scan(4, :match => "key:1?")
# # => ["92", ["key:13", "key:18"]]
+ # @example Retrieve a batch of keys of a certain type
+ # redis.scan(92, :type => "zset")
+ # # => ["173", ["sortedset:14", "sortedset:78"]]
#
# @param [String, Integer] cursor the cursor of the iteration
# @param [Hash] options
# - `:match => String`: only return keys matching the pattern
# - `:count => Integer`: return count keys at most per iteration
+ # - `:type => String`: return keys only of the given type
#
# @return [String, Array<String>] the next cursor and all found keys
def scan(cursor, **options)
_scan(:scan, cursor, [], **options)
end
@@ -2674,13 +2681,18 @@
# # => ["key:21", "key:47", "key:42"]
# @example Execute block for each key matching a pattern
# redis.scan_each(:match => "key:1?") {|key| puts key}
# # => key:13
# # => key:18
+ # @example Execute block for each key of a type
+ # redis.scan_each(:type => "hash") {|key| puts redis.type(key)}
+ # # => "hash"
+ # # => "hash"
#
# @param [Hash] options
# - `:match => String`: only return keys matching the pattern
# - `:count => Integer`: return count keys at most per iteration
+ # - `:type => String`: return keys only of the given type
#
# @return [Enumerator] an enumerator for all found keys
def scan_each(**options, &block)
return to_enum(:scan_each, **options) unless block_given?