Class: Redis::Client

Inherits:
RedisClient
  • Object
show all
Defined in:
lib/redis/client.rb

Constant Summary collapse

ERROR_MAPPING =
{
  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 collapse

Instance Method Summary collapse

Class Method Details

.config(**kwargs) ⇒ Object



25
26
27
# File 'lib/redis/client.rb', line 25

def config(**kwargs)
  super(protocol: 2, **kwargs)
end

.sentinel(**kwargs) ⇒ Object



29
30
31
# File 'lib/redis/client.rb', line 29

def sentinel(**kwargs)
  super(protocol: 2, **kwargs, client_implementation: ::RedisClient)
end

.translate_error!(error, mapping: ERROR_MAPPING) ⇒ Object

Raises:

  • (redis_error)


33
34
35
36
# File 'lib/redis/client.rb', line 33

def translate_error!(error, mapping: ERROR_MAPPING)
  redis_error = translate_error_class(error.class, mapping: mapping)
  raise redis_error, error.message, error.backtrace
end

Instance Method Details

#blocking_call_v(timeout, command, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/redis/client.rb', line 104

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
  Client.translate_error!(error)
end

#call_v(command, &block) ⇒ Object



98
99
100
101
102
# File 'lib/redis/client.rb', line 98

def call_v(command, &block)
  super(command, &block)
rescue ::RedisClient::Error => error
  Client.translate_error!(error)
end

#dbObject



63
64
65
# File 'lib/redis/client.rb', line 63

def db
  config.db
end

#ensure_connected(retryable: true, &block) ⇒ Object



92
93
94
95
96
# File 'lib/redis/client.rb', line 92

def ensure_connected(retryable: true, &block)
  super(retryable: retryable, &block)
rescue ::RedisClient::Error => error
  Client.translate_error!(error)
end

#hostObject



67
68
69
# File 'lib/redis/client.rb', line 67

def host
  config.host unless config.path
end

#idObject



51
52
53
# File 'lib/redis/client.rb', line 51

def id
  config.id
end

#inherit_socket!Object



129
130
131
# File 'lib/redis/client.rb', line 129

def inherit_socket!
  @inherit_socket = true
end

#multi(watch: nil) ⇒ Object



123
124
125
126
127
# File 'lib/redis/client.rb', line 123

def multi(watch: nil)
  super
rescue ::RedisClient::Error => error
  Client.translate_error!(error)
end

#passwordObject



83
84
85
# File 'lib/redis/client.rb', line 83

def password
  config.password
end

#pathObject



75
76
77
# File 'lib/redis/client.rb', line 75

def path
  config.path
end

#pipelined(exception: true) ⇒ Object



117
118
119
120
121
# File 'lib/redis/client.rb', line 117

def pipelined(exception: true)
  super
rescue ::RedisClient::Error => error
  Client.translate_error!(error)
end

#portObject



71
72
73
# File 'lib/redis/client.rb', line 71

def port
  config.port unless config.path
end

#server_urlObject



55
56
57
# File 'lib/redis/client.rb', line 55

def server_url
  config.server_url
end

#timeoutObject



59
60
61
# File 'lib/redis/client.rb', line 59

def timeout
  config.read_timeout
end

#usernameObject



79
80
81
# File 'lib/redis/client.rb', line 79

def username
  config.username
end