File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3+ require 'redis_client'
4+
35class RedisClient
46 class Cluster
57 class PubSub
@@ -76,8 +78,26 @@ def next_event(timeout = nil)
7678
7779 def _call ( command )
7880 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 )
8086 @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 )
81101 end
82102
83103 def obtain_current_time
You can’t perform that action at this time.
0 commit comments