Skip to content

Commit 546ce35

Browse files
committed
Prefer using a local object rather than Thread.current.
1 parent 396894c commit 546ce35

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/redis.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def self.current=(redis)
4949
def initialize(options = {})
5050
@options = options.dup
5151
@original_client = @client = Client.new(options)
52+
@queue = Hash.new { |h, k| h[k] = [] }
5253

5354
super() # Monitor#initialize
5455
end
@@ -101,7 +102,7 @@ def call(*command)
101102
# See http://redis.io/topics/pipelining for more details.
102103
#
103104
def queue(*command)
104-
_queue << command
105+
@queue[Thread.current.object_id] << command
105106
end
106107

107108
# Sends all commands in the queue.
@@ -111,9 +112,9 @@ def queue(*command)
111112
def commit
112113
synchronize do |client|
113114
begin
114-
client.call_pipelined(_queue)
115+
client.call_pipelined(@queue[Thread.current.object_id])
115116
ensure
116-
_queue.clear
117+
@queue.delete(Thread.current.object_id)
117118
end
118119
end
119120
end
@@ -2778,10 +2779,6 @@ def _subscription(method, timeout, channels, block)
27782779
end
27792780
end
27802781

2781-
def _queue
2782-
Thread.current[:redis_queue] ||= []
2783-
end
2784-
27852782
end
27862783

27872784
require "redis/version"

0 commit comments

Comments
 (0)