Skip to content

Commit c3a984e

Browse files
committed
Fix Redis#id inside pipeline blocks.
Closes #383.
1 parent 530d062 commit c3a984e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/redis.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,15 +2415,11 @@ def sscan_each(key, options={}, &block)
24152415
end
24162416

24172417
def id
2418-
synchronize do |client|
2419-
client.id
2420-
end
2418+
@original_client.id
24212419
end
24222420

24232421
def inspect
2424-
synchronize do |client|
2425-
"#<Redis client v#{Redis::VERSION} for #{@original_client.id}>"
2426-
end
2422+
"#<Redis client v#{Redis::VERSION} for #{id}>"
24272423
end
24282424

24292425
def method_missing(command, *args)

test/internals_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ def test_timeout
109109
end
110110
end
111111

112+
def test_id_inside_multi
113+
redis = Redis.new(OPTIONS)
114+
id = nil
115+
116+
redis.multi do
117+
id = redis.id
118+
end
119+
120+
assert_equal id, "redis://127.0.0.1:6381/15"
121+
end
122+
112123
driver(:ruby) do
113124
def test_tcp_keepalive
114125
keepalive = {:time => 20, :intvl => 10, :probes => 5}

0 commit comments

Comments
 (0)