redis-cluster-client 0.4.7 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b894248e71e984932e9d2f177640c86a7f7d08cb57d3bf43bb91603ffe737003
4
- data.tar.gz: e1ca295dc2a19a4c16ecb2b69ef3ad28cd353c5f5b17db90749d29c8b9eb3f79
3
+ metadata.gz: 19e03bc6e2b6ddf57697c9e63dd5ffa729e6621979b3daef02b28062dc328494
4
+ data.tar.gz: f212df153cda0c53710c5f03586c01042d168380982113e4dd354ae859c276b4
5
5
  SHA512:
6
- metadata.gz: 88f12ba8750400ac78ae399d0b1f1301a7d12626286d780a04268af16bc1fab58f2da168b8802766f631fb09327518ca0f6927e2b57f6c03a79b3ec4439b9033
7
- data.tar.gz: f721594b1cf537dc05f7d999f99626814f88f3488bf8f2c3c67fa197214f24a1b5513a25e616666c2c8a840cd3b33c616517e8eb35eee9c169a21a3e63ad86ea
6
+ metadata.gz: e6034b7693d67eaec5e979fe5cce0c310746262971a77642392930ee1dc2be2cefcad6ac3729cc8d11fb3a2d3ba1077ee2aacfef618fc570c688850056f1c1f6
7
+ data.tar.gz: 5182806018f1452094085cea4f2c1bd70ecbfe71d4d5b178fec7f06712debd4cb843fb794ab1b1d29df61204a14db9a0e92eb133f40ffcb732397dd76c7e199f
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'redis_client'
4
+
3
5
  class RedisClient
4
6
  class Cluster
5
7
  class PubSub
@@ -65,7 +67,7 @@ class RedisClient
65
67
  loop do
66
68
  break if max_duration > 0 && obtain_current_time - starting > max_duration
67
69
 
68
- @states.each_value do |pubsub|
70
+ @states.values.shuffle.each do |pubsub|
69
71
  message = pubsub.take_message(timeout)
70
72
  return message if message
71
73
  end
@@ -76,8 +78,26 @@ class RedisClient
76
78
 
77
79
  def _call(command)
78
80
  node_key = @router.find_node_key(command)
79
- @states[node_key] = State.new(@router.find_node(node_key).pubsub) unless @states.key?(node_key)
81
+ add_state(node_key)
82
+ try_call(node_key, command)
83
+ end
84
+
85
+ def try_call(node_key, command, retry_count: 1)
80
86
  @states[node_key].call(command)
87
+ rescue ::RedisClient::CommandError => e
88
+ raise if !e.message.start_with?('MOVED') || retry_count <= 0
89
+
90
+ # for sharded pub/sub
91
+ node_key = e.message.split[2]
92
+ add_state(node_key)
93
+ retry_count -= 1
94
+ retry
95
+ end
96
+
97
+ def add_state(node_key)
98
+ return @states[node_key] if @states.key?(node_key)
99
+
100
+ @states[node_key] = State.new(@router.find_node(node_key).pubsub)
81
101
  end
82
102
 
83
103
  def obtain_current_time
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-10 00:00:00.000000000 Z
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client