Skip to content

Commit

Permalink
Deprecate passing timeout as a positional argument in blocking comm…
Browse files Browse the repository at this point in the history
…ands
  • Loading branch information
byroot committed Aug 22, 2022
1 parent 47a6f93 commit 08eea74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Introduce `sadd?` and `srem?` as boolean returning versions of `sadd` and `srem`.
* Deprecate `sadd` and `srem` returning a boolean when called with a single argument.
To enable the redis 5.0 behavior you can set `Redis.sadd_returns_boolean = true`.
* Deprecate passing `timeout` as a positional argument in blocking commands (`brpop`, `blop`, etc).

# 4.7.1

Expand Down
13 changes: 7 additions & 6 deletions lib/redis/commands/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,17 @@ def _bpop(cmd, args, &blk)
options = args.pop
options[:timeout]
elsif args.last.respond_to?(:to_int)
# Issue deprecation notice in obnoxious mode...
args.pop.to_int
last_arg = args.pop
::Redis.deprecate!(
"Passing the timeout as a positional argument is deprecated, it should be passed as a keyword argument:\n" \
" redis.#{cmd}(#{args.map(&:inspect).join(', ')}, timeout: #{last_arg.to_int})" \
"(called from: #{caller(2, 1).first})"
)
last_arg.to_int
end

timeout ||= 0

if args.size > 1
# Issue deprecation notice in obnoxious mode...
end

keys = args.flatten

command = [cmd, keys, timeout]
Expand Down
13 changes: 7 additions & 6 deletions lib/redis/distributed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,13 @@ def _bpop(cmd, args)
options = args.pop
options[:timeout]
elsif args.last.respond_to?(:to_int)
# Issue deprecation notice in obnoxious mode...
args.pop.to_int
end

if args.size > 1
# Issue deprecation notice in obnoxious mode...
last_arg = args.pop
::Redis.deprecate!(
"Passing the timeout as a positional argument is deprecated, it should be passed as a keyword argument:\n" \
" redis.#{cmd}(#{args.map(&:inspect).join(', ')}, timeout: #{last_arg.to_int})" \
"(called from: #{caller(2, 1).first})"
)
last_arg.to_int
end

keys = args.flatten
Expand Down

0 comments on commit 08eea74

Please sign in to comment.