Skip to content

Commit cc51a08

Browse files
committed
Merge pull request #783 from byroot/fix-bpop-timeout
Handle integer like objects as timeout of blpop and brpop
1 parent 7ff90f1 commit cc51a08

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lib/redis.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,11 @@ def rpoplpush(source, destination)
11591159
def _bpop(cmd, args, &blk)
11601160
options = {}
11611161

1162-
case args.last
1163-
when Hash
1162+
if args.last.is_a?(Hash)
11641163
options = args.pop
1165-
when Integer
1164+
elsif args.last.respond_to?(:to_int)
11661165
# Issue deprecation notice in obnoxious mode...
1167-
options[:timeout] = args.pop
1166+
options[:timeout] = args.pop.to_int
11681167
end
11691168

11701169
if args.size > 1

lib/redis/distributed.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,11 @@ def rpoplpush(source, destination)
403403
def _bpop(cmd, args)
404404
options = {}
405405

406-
case args.last
407-
when Hash
406+
if args.last.is_a?(Hash)
408407
options = args.pop
409-
when Integer
408+
elsif args.last.respond_to?(:to_int)
410409
# Issue deprecation notice in obnoxious mode...
411-
options[:timeout] = args.pop
410+
options[:timeout] = args.pop.to_int
412411
end
413412

414413
if args.size > 1

test/lint/blocking_commands.rb

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ def test_blpop_timeout
6767
end
6868
end
6969

70+
class FakeDuration
71+
def initialize(int)
72+
@int = int
73+
end
74+
75+
def to_int
76+
@int
77+
end
78+
end
79+
80+
def test_blpop_integer_like_timeout
81+
mock do |r|
82+
assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", FakeDuration.new(1))
83+
end
84+
end
85+
7086
def test_blpop_with_old_prototype
7187
assert_equal ['{zap}foo', 's1'], r.blpop('{zap}foo', 0)
7288
assert_equal ['{zap}foo', 's2'], r.blpop('{zap}foo', 0)

0 commit comments

Comments
 (0)