Skip to content

Commit 56e254b

Browse files
authored
perf: prevent waiting for the mutex to be released (#122)
1 parent a86b874 commit 56e254b

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

lib/redis_client/cluster/node.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def any_replica_node_key(seed: nil)
181181
end
182182

183183
def update_slot(slot, node_key)
184+
return if @mutex.locked?
185+
184186
@mutex.synchronize { @slots[slot] = node_key }
185187
end
186188

lib/redis_client/cluster/router.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def fetch_cluster_info(config, pool: nil, **kwargs) # rubocop:disable Metrics/Me
281281
end
282282

283283
def update_cluster_info!
284+
return if @mutex.locked?
285+
284286
@mutex.synchronize do
285287
begin
286288
@node.each(&:close)

lib/redis_client/cluster_config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ def use_replica?
8383
end
8484

8585
def update_node(addrs)
86+
return if @mutex.locked?
87+
8688
@mutex.synchronize { @node_configs = build_node_configs(addrs) }
8789
end
8890

8991
def add_node(host, port)
92+
return if @mutex.locked?
93+
9094
@mutex.synchronize { @node_configs << { host: host, port: port } }
9195
end
9296

0 commit comments

Comments
 (0)