class Redis
Constants
- BASE_PATH
- Deprecated
- SERVER_URL_OPTIONS
- VERSION
Attributes
Public Class Methods
Source
# File lib/redis.rb, line 16 def deprecate!(message) unless silence_deprecations if raise_deprecations raise Deprecated, message else ::Kernel.warn(message) end end end
Source
# File lib/redis.rb, line 65 def initialize(options = {}) @monitor = Monitor.new @options = options.dup @options[:reconnect_attempts] = 1 unless @options.key?(:reconnect_attempts) if ENV["REDIS_URL"] && SERVER_URL_OPTIONS.none? { |o| @options.key?(o) } @options[:url] = ENV["REDIS_URL"] end inherit_socket = @options.delete(:inherit_socket) @subscription_client = nil @client = initialize_client(@options) @client.inherit_socket! if inherit_socket end
Create a new client instance
@param [Hash] options @option options [String] :url (value of the environment variable REDIS_URL) a Redis URL, for a TCP connection:
`redis://:[password]@[hostname]:[port]/[db]` (password, port and database are optional), for a unix socket connection: `unix://[path to Redis socket]`. This overrides all other options.
@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 (1.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 connect and on reconnects @option options [Symbol] :driver Driver to use, currently supported: ‘:ruby`, `:hiredis` @option options [String] :id ID for the client connection, assigns name to current connection by sending
`CLIENT SETNAME`
@option options [Integer, Array<Integer, Float>] :reconnect_attempts Number of attempts trying to connect,
or a list of sleep duration between attempts.
@option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not @option options [String] :name The name of the server group to connect to. @option options [Array] :sentinels List of sentinels to contact
@return [Redis] a new client instance
Public Instance Methods
Source
# File lib/redis.rb, line 90 def close @client.close @subscription_client&.close end
Disconnect the client as quickly and silently as possible.
Source
# File lib/redis.rb, line 85 def connected? @client.connected? || @subscription_client&.connected? end
Test whether or not the client is connected
Source
# File lib/redis.rb, line 124 def connection { host: @client.host, port: @client.port, db: @client.db, id: id, location: "#{@client.host}:#{@client.port}" } end
Source
# File lib/redis.rb, line 116 def inspect "#<Redis client v#{Redis::VERSION} for #{id}>" end
Source
# File lib/redis.rb, line 104 def pipelined(exception: true) synchronize do |client| client.pipelined(exception: exception) do |raw_pipeline| yield PipelinedConnection.new(raw_pipeline, exception: exception) end end end
Source
# File lib/redis.rb, line 80 def without_reconnect(&block) @client.disable_reconnection(&block) end
Run code without the client reconnecting