class Redis
def _client
def _client @client end
def _subscription(method, timeout, channels, block)
def _subscription(method, timeout, channels, block) return @client.call([method] + channels) if subscribed? begin original, @client = @client, SubscribedClient.new(@client) if timeout > 0 @client.send(method, timeout, *channels, &block) else @client.send(method, *channels, &block) end ensure @client = original end end
def close
def close @original_client.disconnect end
def commit
- Sends all commands in the queue.
def commit ::Redis.deprecate!( "Redis#commit is deprecated and will be removed in Redis 5.0.0. Use Redis#pipelined instead. " \ "(called from: #{Kernel.caller(1, 1).first})" ) synchronize do |client| begin pipeline = Pipeline.new(client) @queue[Thread.current.object_id].each do |command| pipeline.call(command) end client.call_pipelined(pipeline) ensure @queue.delete(Thread.current.object_id) end end end
def connected?
def connected? @original_client.connected? end
def connection
def connection return @original_client.connection_info if @cluster_mode { host: @original_client.host, port: @original_client.port, db: @original_client.db, id: @original_client.id, location: @original_client.location } end
def current
def current deprecate!("`Redis.current` is deprecated and will be removed in 5.0. (called from: #{caller(1, 1).first})") @current ||= Redis.new end
def current=(redis)
def current=(redis) deprecate!("`Redis.current=` is deprecated and will be removed in 5.0. (called from: #{caller(1, 1).first})") @current = redis end
def deprecate!(message)
def deprecate!(message) unless silence_deprecations if raise_deprecations raise Deprecated, message else ::Kernel.warn(message) end end end
def dup
def dup self.class.new(@options) end
def exists_returns_integer=(value)
def exists_returns_integer=(value) unless value deprecate!( "`Redis#exists(key)` will return an Integer by default in redis-rb 4.3. The option to explicitly " \ "disable this behaviour via `Redis.exists_returns_integer` will be removed in 5.0. You should use " \ "`exists?` instead." ) end @exists_returns_integer = value end
def id
def id @original_client.id end
def initialize(options = {})
-
(Redis)
- a new client instance
Options Hash:
(**options)
-
:connector
(Class
) -- Class of custom connector -
:fixed_hostname
(String
) -- Specify a FQDN if cluster mode enabled and -
:replica
(Boolean
) -- Whether to use readonly replica nodes in Redis Cluster or not -
:cluster
(Array
) -- List of cluster nodes to contactString, Integer}> -
:role
(Symbol
) -- Role to fetch via Sentinel, either `:master` or `:slave` -
:sentinels
(Array
) -- List of sentinels to contact -
:inherit_socket
(Boolean
) -- Whether to use socket in forked process or not -
:reconnect_attempts
(Integer
) -- Number of attempts trying to connect -
:tcp_keepalive
(Hash, Integer
) -- Keepalive values, if Integer `intvl` and `probe` are calculated -
:id
(String
) -- ID for the client connection, assigns name to current connection by sending -
:driver
(Symbol
) -- Driver to use, currently supported: `:ruby`, `:hiredis`, `:synchrony` -
:db
(Integer
) -- Database to select after initial connect -
:password
(String
) -- Password to authenticate against server -
:username
(String
) -- Username to authenticate against server -
:connect_timeout
(Float
) -- timeout for initial connect in seconds -
:timeout
(Float
) -- timeout in seconds -
:path
(String
) -- path to server socket (overrides host and port) -
:port
(Integer
) -- server port -
:host
(String
) -- server hostname -
:url
(String
) -- a Redis URL, for a TCP connection:
Parameters:
-
options
(Hash
) --
def initialize(options = {}) @options = options.dup @cluster_mode = options.key?(:cluster) client = @cluster_mode ? Cluster : Client @original_client = @client = client.new(options) @queue = Hash.new { |h, k| h[k] = [] } @monitor = Monitor.new end
def inspect
def inspect "#<Redis client v#{Redis::VERSION} for #{id}>" end
def multi(&block)
- See: #unwatch -
See: #watch -
Returns:
-
(String, Array<...>)
-
Other tags:
- Yieldparam: multi - `self`
Other tags:
- Yield: - the commands that are called inside this block are cached
Other tags:
- Example: Without a block -
Example: With a block -
def multi(&block) if block_given? deprecation_displayed = false if block&.arity == 0 Pipeline.deprecation_warning("multi", Kernel.caller_locations(1, 5)) deprecation_displayed = true end synchronize do |prior_client| begin pipeline = Pipeline::Multi.new(prior_client) @client = deprecation_displayed ? pipeline : DeprecatedMulti.new(pipeline) pipelined_connection = PipelinedConnection.new(pipeline) yield pipelined_connection prior_client.call_pipeline(pipeline) ensure @client = prior_client end end else send_command([:multi]) end end
def pipelined(&block)
def pipelined(&block) deprecation_displayed = false if block&.arity == 0 Pipeline.deprecation_warning("pipelined", Kernel.caller_locations(1, 5)) deprecation_displayed = true end synchronize do |prior_client| begin pipeline = Pipeline.new(prior_client) @client = deprecation_displayed ? pipeline : DeprecatedPipeline.new(pipeline) pipelined_connection = PipelinedConnection.new(pipeline) yield pipelined_connection prior_client.call_pipeline(pipeline) ensure @client = prior_client end end end
def queue(*command)
- Queues a command for pipelining.
def queue(*command) ::Redis.deprecate!( "Redis#queue is deprecated and will be removed in Redis 5.0.0. Use Redis#pipelined instead." \ "(called from: #{caller(1, 1).first})" ) synchronize do @queue[Thread.current.object_id] << command end end
def send_blocking_command(command, timeout, &block)
def send_blocking_command(command, timeout, &block) @monitor.synchronize do @client.call_with_timeout(command, timeout, &block) end end
def send_command(command, &block)
def send_command(command, &block) @monitor.synchronize do @client.call(command, &block) end end
def synchronize
def synchronize @monitor.synchronize { yield(@client) } end
def with
def with yield self end
def with_reconnect(val = true, &blk)
def with_reconnect(val = true, &blk) synchronize do |client| client.with_reconnect(val, &blk) end end
def without_reconnect(&blk)
def without_reconnect(&blk) with_reconnect(false, &blk) end