Class: Redis::Cluster::Client
- Inherits:
-
RedisClient::Cluster
- Object
- RedisClient::Cluster
- Redis::Cluster::Client
- Defined in:
- lib/redis/cluster/client.rb
Constant Summary collapse
- ERROR_MAPPING =
::Redis::Client::ERROR_MAPPING.merge( RedisClient::Cluster::InitialSetupError => Redis::Cluster::InitialSetupError, RedisClient::Cluster::OrchestrationCommandNotSupported => Redis::Cluster::OrchestrationCommandNotSupported, RedisClient::Cluster::AmbiguousNodeError => Redis::Cluster::AmbiguousNodeError, RedisClient::Cluster::ErrorCollection => Redis::Cluster::CommandErrorCollection, RedisClient::Cluster::Transaction::ConsistencyError => Redis::Cluster::TransactionConsistencyError, RedisClient::Cluster::NodeMightBeDown => Redis::Cluster::NodeMightBeDown, )
Class Method Summary collapse
- .config(**kwargs) ⇒ Object
- .sentinel(**kwargs) ⇒ Object
- .translate_error!(error, mapping: ERROR_MAPPING) ⇒ Object
Instance Method Summary collapse
- #blocking_call_v(timeout, command, &block) ⇒ Object
- #call_v(command, &block) ⇒ Object
- #connected? ⇒ Boolean
- #db ⇒ Object
- #disable_reconnection ⇒ Object
- #id ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #multi(watch: nil, &block) ⇒ Object
- #pipelined(exception: true, &block) ⇒ Object
- #server_url ⇒ Object
- #timeout ⇒ Object
- #watch(*keys, &block) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
51 52 53 |
# File 'lib/redis/cluster/client.rb', line 51 def initialize(*) handle_errors { super } end |
Class Method Details
.config(**kwargs) ⇒ Object
19 20 21 |
# File 'lib/redis/cluster/client.rb', line 19 def config(**kwargs) super(protocol: 2, **kwargs) end |
.sentinel(**kwargs) ⇒ Object
23 24 25 |
# File 'lib/redis/cluster/client.rb', line 23 def sentinel(**kwargs) super(protocol: 2, **kwargs) end |
.translate_error!(error, mapping: ERROR_MAPPING) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/redis/cluster/client.rb', line 27 def translate_error!(error, mapping: ERROR_MAPPING) case error when RedisClient::Cluster::ErrorCollection error.errors.each do |_node, node_error| if node_error.is_a?(RedisClient::AuthenticationError) raise mapping.fetch(node_error.class), node_error., node_error.backtrace end end remapped_node_errors = error.errors.map do |node_key, node_error| remapped = mapping.fetch(node_error.class, node_error.class).new(node_error.) remapped.set_backtrace node_error.backtrace [node_key, remapped] end.to_h raise(Redis::Cluster::CommandErrorCollection.new(remapped_node_errors, error.).tap do |remapped| remapped.set_backtrace error.backtrace end) else Redis::Client.translate_error!(error, mapping: mapping) end end |
Instance Method Details
#blocking_call_v(timeout, command, &block) ⇒ Object
89 90 91 92 |
# File 'lib/redis/cluster/client.rb', line 89 def blocking_call_v(timeout, command, &block) timeout += self.timeout if timeout && timeout > 0 handle_errors { super(timeout, command, &block) } end |
#call_v(command, &block) ⇒ Object
85 86 87 |
# File 'lib/redis/cluster/client.rb', line 85 def call_v(command, &block) handle_errors { super(command, &block) } end |
#connected? ⇒ Boolean
64 65 66 |
# File 'lib/redis/cluster/client.rb', line 64 def connected? true end |
#db ⇒ Object
76 77 78 |
# File 'lib/redis/cluster/client.rb', line 76 def db 0 end |
#disable_reconnection ⇒ Object
68 69 70 |
# File 'lib/redis/cluster/client.rb', line 68 def disable_reconnection yield # TODO: do we need this, is it doable? end |
#id ⇒ Object
56 57 58 |
# File 'lib/redis/cluster/client.rb', line 56 def id server_url.join(' ') end |
#multi(watch: nil, &block) ⇒ Object
98 99 100 |
# File 'lib/redis/cluster/client.rb', line 98 def multi(watch: nil, &block) handle_errors { super(watch: watch, &block) } end |
#pipelined(exception: true, &block) ⇒ Object
94 95 96 |
# File 'lib/redis/cluster/client.rb', line 94 def pipelined(exception: true, &block) handle_errors { super(exception: exception, &block) } end |
#server_url ⇒ Object
60 61 62 |
# File 'lib/redis/cluster/client.rb', line 60 def server_url @router.nil? ? @config.startup_nodes.keys : router.node_keys end |
#timeout ⇒ Object
72 73 74 |
# File 'lib/redis/cluster/client.rb', line 72 def timeout config.read_timeout end |
#watch(*keys, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/redis/cluster/client.rb', line 102 def watch(*keys, &block) unless block_given? raise( Redis::Cluster::TransactionConsistencyError, 'A block is required if you use the cluster client.' ) end unless block.arity == 1 raise( Redis::Cluster::TransactionConsistencyError, 'Given block needs an argument if you use the cluster client.' ) end handle_errors do RedisClient::Cluster::OptimisticLocking.new(router).watch(keys) do |c, slot, asking| transaction = Redis::Cluster::TransactionAdapter.new( self, router, @command_builder, node: c, slot: slot, asking: asking ) result = yield transaction c.call('UNWATCH') unless transaction.lock_released? result end end end |