Skip to content

Commit 9a7760d

Browse files
committed
Fix timeout error on xread w/ block 0 option and resolve #836
1 parent df07a4c commit 9a7760d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/redis.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,8 @@ def _xread(args, keys, ids, blocking_timeout_msec)
34703470
synchronize do |client|
34713471
if blocking_timeout_msec.nil?
34723472
client.call(args, &HashifyStreams)
3473+
elsif blocking_timeout_msec.to_f.zero?
3474+
client.call_without_timeout(args, &HashifyStreams)
34733475
else
34743476
timeout = client.timeout.to_f + blocking_timeout_msec.to_f / 1000.0
34753477
client.call_with_timeout(args, timeout, &HashifyStreams)

test/lint/streams.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@ def test_xread_with_block_option
346346
assert_equal({}, actual)
347347
end
348348

349+
def test_xread_does_not_raise_timeout_error_when_the_block_option_is_zero_msec
350+
prepared = false
351+
actual = nil
352+
wire = Wire.new do
353+
prepared = true
354+
actual = redis.xread('s1', 0, block: 0)
355+
end
356+
Wire.pass until prepared
357+
redis.dup.xadd('s1', { f: 'v1' }, id: '0-1')
358+
wire.join
359+
360+
assert_equal ['v1'], actual.fetch('s1').map { |i| i.last['f'] }
361+
end
362+
349363
def test_xread_with_invalid_arguments
350364
assert_raise(Redis::CommandError) { redis.xread(nil, nil) }
351365
assert_raise(Redis::CommandError) { redis.xread('', '') }

0 commit comments

Comments
 (0)