redis-cluster-client 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/redis_client/cluster/errors.rb +1 -1
 - data/lib/redis_client/cluster/node.rb +6 -6
 - data/lib/redis_client/cluster.rb +20 -11
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: aff938c0517542c32f98206c28f1f605a52751e2e2e9a1bd10f5576285f568ee
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8a3d45fba93334959b1ee67504d2703bb116a8133ef8dac2aa8f314fdb74b268
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 63dec0155a50a0dbb7a17763c43291d371abe4e3df407340ba8edf125cf2c2bb338f607026a1d004dca489761cb2e6b5450e68a468f18799e5c3443b52a21be7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4de6c4688ca120d7f4b636bd884195b3cddc3bf8d217ea662a1f382ced46de2c9e24b0e967a801d175f0572a083b9e5ea835d54797422cf60ce799cda3002f74
         
     | 
| 
         @@ -118,7 +118,7 @@ class RedisClient 
     | 
|
| 
       118 
118 
     | 
    
         
             
                    try_map { |_, client| client.send(method, *command, **kwargs, &block) }.values
         
     | 
| 
       119 
119 
     | 
    
         
             
                  end
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                  def  
     | 
| 
      
 121 
     | 
    
         
            +
                  def call_primaries(method, *command, **kwargs, &block)
         
     | 
| 
       122 
122 
     | 
    
         
             
                    try_map do |node_key, client|
         
     | 
| 
       123 
123 
     | 
    
         
             
                      next if replica?(node_key)
         
     | 
| 
       124 
124 
     | 
    
         | 
| 
         @@ -126,8 +126,8 @@ class RedisClient 
     | 
|
| 
       126 
126 
     | 
    
         
             
                    end.values
         
     | 
| 
       127 
127 
     | 
    
         
             
                  end
         
     | 
| 
       128 
128 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
                  def  
     | 
| 
       130 
     | 
    
         
            -
                    return  
     | 
| 
      
 129 
     | 
    
         
            +
                  def call_replicas(method, *command, **kwargs, &block)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    return call_primaries(method, *command, **kwargs, &block) if replica_disabled?
         
     | 
| 
       131 
131 
     | 
    
         | 
| 
       132 
132 
     | 
    
         
             
                    replica_node_keys = @replications.values.map(&:sample)
         
     | 
| 
       133 
133 
     | 
    
         
             
                    try_map do |node_key, client|
         
     | 
| 
         @@ -228,14 +228,14 @@ class RedisClient 
     | 
|
| 
       228 
228 
     | 
    
         
             
                  end
         
     | 
| 
       229 
229 
     | 
    
         | 
| 
       230 
230 
     | 
    
         
             
                  def try_map # rubocop:disable Metrics/MethodLength
         
     | 
| 
       231 
     | 
    
         
            -
                    errors = {}
         
     | 
| 
       232 
231 
     | 
    
         
             
                    results = {}
         
     | 
| 
      
 232 
     | 
    
         
            +
                    errors = {}
         
     | 
| 
       233 
233 
     | 
    
         
             
                    threads = @clients.map do |k, v|
         
     | 
| 
       234 
234 
     | 
    
         
             
                      Thread.new(k, v) do |node_key, client|
         
     | 
| 
       235 
235 
     | 
    
         
             
                        Thread.pass
         
     | 
| 
       236 
236 
     | 
    
         
             
                        reply = yield(node_key, client)
         
     | 
| 
       237 
237 
     | 
    
         
             
                        results[node_key] = reply unless reply.nil?
         
     | 
| 
       238 
     | 
    
         
            -
                      rescue  
     | 
| 
      
 238 
     | 
    
         
            +
                      rescue StandardError => e
         
     | 
| 
       239 
239 
     | 
    
         
             
                        errors[node_key] = e
         
     | 
| 
       240 
240 
     | 
    
         
             
                      end
         
     | 
| 
       241 
241 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -243,7 +243,7 @@ class RedisClient 
     | 
|
| 
       243 
243 
     | 
    
         
             
                    threads.each(&:join)
         
     | 
| 
       244 
244 
     | 
    
         
             
                    return results if errors.empty?
         
     | 
| 
       245 
245 
     | 
    
         | 
| 
       246 
     | 
    
         
            -
                    raise ::RedisClient::Cluster:: 
     | 
| 
      
 246 
     | 
    
         
            +
                    raise ::RedisClient::Cluster::ErrorCollection, errors
         
     | 
| 
       247 
247 
     | 
    
         
             
                  end
         
     | 
| 
       248 
248 
     | 
    
         
             
                end
         
     | 
| 
       249 
249 
     | 
    
         
             
              end
         
     | 
    
        data/lib/redis_client/cluster.rb
    CHANGED
    
    | 
         @@ -40,9 +40,10 @@ class RedisClient 
     | 
|
| 
       40 
40 
     | 
    
         
             
                    @size.zero?
         
     | 
| 
       41 
41 
     | 
    
         
             
                  end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                  # TODO: https://github.com/redis-rb/redis-cluster-client/issues/37
         
     | 
| 
       44 
     | 
    
         
            -
                  def execute # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
         
     | 
| 
      
 43 
     | 
    
         
            +
                  # TODO: https://github.com/redis-rb/redis-cluster-client/issues/37 handle redirections
         
     | 
| 
      
 44 
     | 
    
         
            +
                  def execute # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
         
     | 
| 
       45 
45 
     | 
    
         
             
                    all_replies = Array.new(@size)
         
     | 
| 
      
 46 
     | 
    
         
            +
                    errors = {}
         
     | 
| 
       46 
47 
     | 
    
         
             
                    threads = @grouped.map do |k, v|
         
     | 
| 
       47 
48 
     | 
    
         
             
                      Thread.new(@client, k, v) do |client, node_key, rows|
         
     | 
| 
       48 
49 
     | 
    
         
             
                        Thread.pass
         
     | 
| 
         @@ -60,11 +61,15 @@ class RedisClient 
     | 
|
| 
       60 
61 
     | 
    
         
             
                        raise ReplySizeError, "commands: #{rows.size}, replies: #{replies.size}" if rows.size != replies.size
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
       62 
63 
     | 
    
         
             
                        rows.each_with_index { |row, idx| all_replies[row.first] = replies[idx] }
         
     | 
| 
      
 64 
     | 
    
         
            +
                      rescue StandardError => e
         
     | 
| 
      
 65 
     | 
    
         
            +
                        errors[node_key] = e
         
     | 
| 
       63 
66 
     | 
    
         
             
                      end
         
     | 
| 
       64 
67 
     | 
    
         
             
                    end
         
     | 
| 
       65 
68 
     | 
    
         | 
| 
       66 
69 
     | 
    
         
             
                    threads.each(&:join)
         
     | 
| 
       67 
     | 
    
         
            -
                    all_replies
         
     | 
| 
      
 70 
     | 
    
         
            +
                    return all_replies if errors.empty?
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    raise ::RedisClient::Cluster::ErrorCollection, errors
         
     | 
| 
       68 
73 
     | 
    
         
             
                  end
         
     | 
| 
       69 
74 
     | 
    
         
             
                end
         
     | 
| 
       70 
75 
     | 
    
         | 
| 
         @@ -185,10 +190,10 @@ class RedisClient 
     | 
|
| 
       185 
190 
     | 
    
         
             
                  when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save', 'ping'
         
     | 
| 
       186 
191 
     | 
    
         
             
                    @node.call_all(method, *command, **kwargs, &block).first
         
     | 
| 
       187 
192 
     | 
    
         
             
                  when 'flushall', 'flushdb'
         
     | 
| 
       188 
     | 
    
         
            -
                    @node. 
     | 
| 
      
 193 
     | 
    
         
            +
                    @node.call_primaries(method, *command, **kwargs, &block).first
         
     | 
| 
       189 
194 
     | 
    
         
             
                  when 'wait'     then send_wait_command(method, *command, **kwargs, &block)
         
     | 
| 
       190 
     | 
    
         
            -
                  when 'keys'     then @node. 
     | 
| 
       191 
     | 
    
         
            -
                  when 'dbsize'   then @node. 
     | 
| 
      
 195 
     | 
    
         
            +
                  when 'keys'     then @node.call_replicas(method, *command, **kwargs, &block).flatten.sort
         
     | 
| 
      
 196 
     | 
    
         
            +
                  when 'dbsize'   then @node.call_replicas(method, *command, **kwargs, &block).sum
         
     | 
| 
       192 
197 
     | 
    
         
             
                  when 'scan'     then _scan(*command, **kwargs)
         
     | 
| 
       193 
198 
     | 
    
         
             
                  when 'lastsave' then @node.call_all(method, *command, **kwargs, &block).sort
         
     | 
| 
       194 
199 
     | 
    
         
             
                  when 'role'     then @node.call_all(method, *command, **kwargs, &block)
         
     | 
| 
         @@ -206,14 +211,14 @@ class RedisClient 
     | 
|
| 
       206 
211 
     | 
    
         
             
                    node = assign_node(*command)
         
     | 
| 
       207 
212 
     | 
    
         
             
                    try_send(node, method, *command, **kwargs, &block)
         
     | 
| 
       208 
213 
     | 
    
         
             
                  end
         
     | 
| 
       209 
     | 
    
         
            -
                rescue RedisClient::Cluster:: 
     | 
| 
      
 214 
     | 
    
         
            +
                rescue RedisClient::Cluster::ErrorCollection => e
         
     | 
| 
       210 
215 
     | 
    
         
             
                  update_cluster_info! if e.errors.values.map(&:class).any?(::RedisClient::ConnectionError)
         
     | 
| 
       211 
216 
     | 
    
         
             
                  raise
         
     | 
| 
       212 
217 
     | 
    
         
             
                end
         
     | 
| 
       213 
218 
     | 
    
         | 
| 
       214 
219 
     | 
    
         
             
                def send_wait_command(method, *command, retry_count: 3, **kwargs, &block)
         
     | 
| 
       215 
     | 
    
         
            -
                  @node. 
     | 
| 
       216 
     | 
    
         
            -
                rescue RedisClient::Cluster:: 
     | 
| 
      
 220 
     | 
    
         
            +
                  @node.call_primaries(method, *command, **kwargs, &block).sum
         
     | 
| 
      
 221 
     | 
    
         
            +
                rescue RedisClient::Cluster::ErrorCollection => e
         
     | 
| 
       217 
222 
     | 
    
         
             
                  raise if retry_count <= 0 || e.errors.values.map(&:message).grep(/ERR WAIT cannot be used with replica instances/).empty?
         
     | 
| 
       218 
223 
     | 
    
         | 
| 
       219 
224 
     | 
    
         
             
                  update_cluster_info!
         
     | 
| 
         @@ -246,13 +251,17 @@ class RedisClient 
     | 
|
| 
       246 
251 
     | 
    
         
             
                  end
         
     | 
| 
       247 
252 
     | 
    
         
             
                end
         
     | 
| 
       248 
253 
     | 
    
         | 
| 
       249 
     | 
    
         
            -
                def send_cluster_command(method, *command, **kwargs, &block)
         
     | 
| 
      
 254 
     | 
    
         
            +
                def send_cluster_command(method, *command, **kwargs, &block) # rubocop:disable Metrics/MethodLength
         
     | 
| 
       250 
255 
     | 
    
         
             
                  subcommand = command[1].to_s.downcase
         
     | 
| 
       251 
256 
     | 
    
         
             
                  case subcommand
         
     | 
| 
       252 
257 
     | 
    
         
             
                  when 'addslots', 'delslots', 'failover', 'forget', 'meet', 'replicate',
         
     | 
| 
       253 
258 
     | 
    
         
             
                       'reset', 'set-config-epoch', 'setslot'
         
     | 
| 
       254 
259 
     | 
    
         
             
                    raise ::RedisClient::Cluster::OrchestrationCommandNotSupported, ['cluster', subcommand]
         
     | 
| 
       255 
260 
     | 
    
         
             
                  when 'saveconfig' then @node.call_all(method, *command, **kwargs, &block).first
         
     | 
| 
      
 261 
     | 
    
         
            +
                  when 'getkeysinslot'
         
     | 
| 
      
 262 
     | 
    
         
            +
                    raise ArgumentError, command.join(' ') if command.size != 4
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
                    find_node(@node.find_node_key_of_replica(command[2])).send(method, *command, **kwargs, &block)
         
     | 
| 
       256 
265 
     | 
    
         
             
                  else assign_node(*command).send(method, *command, **kwargs, &block)
         
     | 
| 
       257 
266 
     | 
    
         
             
                  end
         
     | 
| 
       258 
267 
     | 
    
         
             
                end
         
     | 
| 
         @@ -262,7 +271,7 @@ class RedisClient 
     | 
|
| 
       262 
271 
     | 
    
         
             
                  when 'debug', 'kill'
         
     | 
| 
       263 
272 
     | 
    
         
             
                    @node.call_all(method, *command, **kwargs, &block).first
         
     | 
| 
       264 
273 
     | 
    
         
             
                  when 'flush', 'load'
         
     | 
| 
       265 
     | 
    
         
            -
                    @node. 
     | 
| 
      
 274 
     | 
    
         
            +
                    @node.call_primaries(method, *command, **kwargs, &block).first
         
     | 
| 
       266 
275 
     | 
    
         
             
                  else assign_node(*command).send(method, *command, **kwargs, &block)
         
     | 
| 
       267 
276 
     | 
    
         
             
                  end
         
     | 
| 
       268 
277 
     | 
    
         
             
                end
         
     |