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,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



30
31
32
33
34
# File 'lib/redis/client.rb', line 30

def initialize(*)
  super
  @inherit_socket = false
  @pid = Process.pid
end

Class Method Details

.config(**kwargs) ⇒ Object



21
22
23
# File 'lib/redis/client.rb', line 21

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

.sentinel(**kwargs) ⇒ Object



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

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

Instance Method Details

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



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/redis/client.rb', line 84

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 an extra 100ms to account for
    # the network delay.
    timeout += 0.1
  end

  super(timeout, command, &block)
rescue ::RedisClient::Error => error
  raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end

#call_v(command, &block) ⇒ Object



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

def call_v(command, &block)
  super(command, &block)
rescue ::RedisClient::Error => error
  raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end

#dbObject



49
50
51
# File 'lib/redis/client.rb', line 49

def db
  config.db
end

#disable_reconnection(&block) ⇒ Object



109
110
111
# File 'lib/redis/client.rb', line 109

def disable_reconnection(&block)
  ensure_connected(retryable: false, &block)
end

#hostObject



53
54
55
# File 'lib/redis/client.rb', line 53

def host
  config.host unless config.path
end

#idObject



37
38
39
# File 'lib/redis/client.rb', line 37

def id
  config.id
end

#inherit_socket!Object



113
114
115
# File 'lib/redis/client.rb', line 113

def inherit_socket!
  @inherit_socket = true
end

#multiObject



103
104
105
106
107
# File 'lib/redis/client.rb', line 103

def multi
  super
rescue ::RedisClient::Error => error
  raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end

#passwordObject



69
70
71
# File 'lib/redis/client.rb', line 69

def password
  config.password
end

#pathObject



61
62
63
# File 'lib/redis/client.rb', line 61

def path
  config.path
end

#pipelinedObject



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

def pipelined
  super
rescue ::RedisClient::Error => error
  raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end

#portObject



57
58
59
# File 'lib/redis/client.rb', line 57

def port
  config.port unless config.path
end

#server_urlObject



41
42
43
# File 'lib/redis/client.rb', line 41

def server_url
  config.server_url
end

#timeoutObject



45
46
47
# File 'lib/redis/client.rb', line 45

def timeout
  config.read_timeout
end

#usernameObject



65
66
67
# File 'lib/redis/client.rb', line 65

def username
  config.username
end