File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 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
@@ -76,8 +78,26 @@ def next_event(timeout = nil)
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
You can’t perform that action at this time.
0 commit comments