redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

blpop raises exception for non-integer timeout

Open cbatson opened this issue 4 years ago • 1 comments

Issue: Calling Redis#blpop with a non-integer timeout option results in an exception.

Expected behavior: Fractional timeouts should be permitted and passed on to Redis.

Version: redis gem version 4.2.5

Detail: redis gem incorrectly requires timeout option of blpop to be an integer:

root@docker-desktop:~# irb
irb(main):001:0> require 'redis'
=> true
irb(main):002:0> redis = Redis.new(host: 'host.docker.internal', port: 6379)
=> #<Redis client v4.2.5 for redis://host.docker.internal:6379/0>
irb(main):003:0> redis.blpop('key', timeout: 0.5)
Traceback (most recent call last):
       15: from /usr/local/bin/irb:23:in `<main>'
       14: from /usr/local/bin/irb:23:in `load'
       13: from /usr/local/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
       12: from (irb):3:in `<main>'
       11: from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:1250:in `blpop'
       10: from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:1221:in `_bpop'
        9: from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
        8: from /usr/local/lib/ruby/3.0.0/monitor.rb:202:in `mon_synchronize'
        7: from /usr/local/lib/ruby/3.0.0/monitor.rb:202:in `synchronize'
        6: from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
        5: from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:1224:in `block in _bpop'
        4: from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:225:in `call_with_timeout'
        3: from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:300:in `with_socket_timeout'
        2: from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:226:in `block in call_with_timeout'
        1: from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:132:in `call'
Redis::CommandError (ERR timeout is not an integer or out of range)

Redis documentation indicates that the timeout argument is interpreted as a double:

The timeout argument is interpreted as a double value specifying the maximum number of seconds to block.

Indeed, fractional timeouts are accepted by Reds:

$ nc localhost 6379
BLPOP key 0.5
*-1

cbatson avatar Feb 23 '21 19:02 cbatson

Only redis 6+ interprets it as a double. Earlier versions return an error so this would break compatibility.

mperham avatar Jun 30 '21 03:06 mperham

Note to self: let's fix this for 5.0

byroot avatar Aug 17 '22 19:08 byroot