Skip to content

Commit

Permalink
Refactor Redis#synchronize and make it private
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 21, 2022
1 parent c30c510 commit 5e6da6e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def current=(redis)
end

include Commands
include MonitorMixin

# Create a new client instance
#
Expand Down Expand Up @@ -76,12 +75,7 @@ def initialize(options = {})
client = @cluster_mode ? Cluster : Client
@original_client = @client = client.new(options)
@queue = Hash.new { |h, k| h[k] = [] }

super() # Monitor#initialize
end

def synchronize
mon_synchronize { yield(@client) }
@monitor = Monitor.new
end

# Run code with the client reconnecting
Expand Down Expand Up @@ -252,15 +246,19 @@ def connection

private

def synchronize
@monitor.synchronize { yield(@client) }
end

def send_command(command, &block)
synchronize do |client|
client.call(command, &block)
@monitor.synchronize do
@client.call(command, &block)
end
end

def send_blocking_command(command, timeout, &block)
synchronize do |client|
client.call_with_timeout(command, timeout, &block)
@monitor.synchronize do
@client.call_with_timeout(command, timeout, &block)
end
end

Expand Down

0 comments on commit 5e6da6e

Please sign in to comment.