Class: Redis::Client
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
RedisClient
|
|
|
Instance Chain:
self,
RedisClient
|
|
| Inherits: |
RedisClient
|
| Defined in: | lib/redis/client.rb |
Constant Summary
-
ERROR_MAPPING =
# File 'lib/redis/client.rb', line 5{ RedisClient::ConnectionError => Redis::ConnectionError, RedisClient::CommandError => Redis::CommandError, RedisClient::ReadTimeoutError => Redis::TimeoutError, RedisClient::CannotConnectError => Redis::CannotConnectError, RedisClient::AuthenticationError => Redis::CannotConnectError, RedisClient::FailoverError => Redis::CannotConnectError, RedisClient::PermissionError => Redis::PermissionError, RedisClient::WrongTypeError => Redis::WrongTypeError, RedisClient::ReadOnlyError => Redis::ReadOnlyError, RedisClient::ProtocolError => Redis::ProtocolError, RedisClient::OutOfMemoryError => Redis::OutOfMemoryError, }
Class Method Summary
- .config(protocol: 3, **kwargs)
-
.resp3_unsupported?(error) ⇒ Boolean
Whether
errorraised during the connection handshake means the server can't speak RESP3 (so we should retry the connection as RESP2). - .sentinel(protocol: 3, **kwargs)
- .translate_error!(error, mapping: ERROR_MAPPING)
- .translate_error_class(error_class, mapping: ERROR_MAPPING) private
Instance Method Summary
Class Method Details
.config(protocol: 3, **kwargs)
[ GitHub ]# File 'lib/redis/client.rb', line 23
def config(protocol: 3, **kwargs) super(protocol: protocol, **kwargs) end
.resp3_unsupported?(error) ⇒ Boolean
Whether error raised during the connection handshake means the server can't speak RESP3
(so we should retry the connection as RESP2). Covers Redis < 6 (no HELLO command, surfaced
by redis-client as UnsupportedServer) and any server replying NOPROTO to HELLO 3.
# File 'lib/redis/client.rb', line 39
def resp3_unsupported?(error) return true if error.is_a?(::RedisClient::UnsupportedServer) return true if error.is_a?(::RedisClient::CommandError) && error..include?("NOPROTO") # Redis::Cluster discovers its topology by connecting to each startup node. When those nodes # don't speak RESP3, redis-cluster-client collects the per-node failures and re-raises them # wrapped in an InitialSetupError, discarding the original error classes (see # RedisClient::Cluster::InitialSetupError.from_errors). Only the concatenated message # survives, so match it to still trigger the RESP2 fallback for pre-6.0 clusters. Guarded by # defined? because the cluster error class is only loaded with the redis-clustering gem. defined?(::RedisClient::Cluster::InitialSetupError) && error.is_a?(::RedisClient::Cluster::InitialSetupError) && (error..include?("NOPROTO") || error..include?("HELLO command")) end
.sentinel(protocol: 3, **kwargs)
[ GitHub ]# File 'lib/redis/client.rb', line 27
def sentinel(protocol: 3, **kwargs) super(protocol: protocol, **kwargs, client_implementation: ::RedisClient) end
.translate_error!(error, mapping: ERROR_MAPPING)
# File 'lib/redis/client.rb', line 31
def translate_error!(error, mapping: ERROR_MAPPING) redis_error = translate_error_class(error.class, mapping: mapping) raise redis_error, error., error.backtrace end
.translate_error_class(error_class, mapping: ERROR_MAPPING) (private)
[ GitHub ]# File 'lib/redis/client.rb', line 56
def translate_error_class(error_class, mapping: ERROR_MAPPING) mapping.fetch(error_class) rescue IndexError if (client_error = error_class.ancestors.find { |a| mapping[a] }) mapping[error_class] = mapping[client_error] else raise end end
Instance Method Details
#blocking_call_v(timeout, command, &block)
[ GitHub ]# File 'lib/redis/client.rb', line 125
def blocking_call_v(timeout, command, &block) if timeout && timeout > 0 # Can't use the command timeout argument as the connection timeout # otherwise it would be very racy. So we add the regular read_timeout on top # to account for the network delay. timeout += config.read_timeout end super(timeout, command, &block) rescue ::RedisClient::Error => error raise if Client.resp3_unsupported?(error) Client.translate_error!(error) end
#call_v(command, &block)
We default to RESP3. Servers that can't speak it reject the HELLO 3 handshake (Redis < 6.0
has no HELLO at all; others answer NOPROTO). Re-raise those errors untranslated so they reach
Redis#with_protocol_fallback as RedisClient::Error and trigger a transparent rebuild as RESP2 —
the same path the sentinel and cluster clients already use. Everything else is translated to
the matching Redis::* error.
# File 'lib/redis/client.rb', line 117
def call_v(command, &block) super(command, &block) rescue ::RedisClient::Error => error raise if Client.resp3_unsupported?(error) Client.translate_error!(error) end
#db
[ GitHub ]# File 'lib/redis/client.rb', line 79
def db config.db end
#host
[ GitHub ]#id
[ GitHub ]# File 'lib/redis/client.rb', line 67
def id config.id end
#inherit_socket!
[ GitHub ]# File 'lib/redis/client.rb', line 156
def inherit_socket! @inherit_socket = true end
#multi(watch: nil)
[ GitHub ]# File 'lib/redis/client.rb', line 148
def multi(watch: nil) super rescue ::RedisClient::Error => error raise if Client.resp3_unsupported?(error) Client.translate_error!(error) end
#password
[ GitHub ]# File 'lib/redis/client.rb', line 103
def password config.password end
#path
[ GitHub ]# File 'lib/redis/client.rb', line 95
def path config.path end
#pipelined(exception: true)
[ GitHub ]# File 'lib/redis/client.rb', line 140
def pipelined(exception: true) super rescue ::RedisClient::Error => error raise if Client.resp3_unsupported?(error) Client.translate_error!(error) end
#port
[ GitHub ]#protocol
[ GitHub ]# File 'lib/redis/client.rb', line 83
def protocol config.protocol end
#server_url
[ GitHub ]# File 'lib/redis/client.rb', line 71
def server_url config.server_url end
#timeout
[ GitHub ]# File 'lib/redis/client.rb', line 75
def timeout config.read_timeout end
#username
[ GitHub ]# File 'lib/redis/client.rb', line 99
def username config.username end