Skip to content

Commit

Permalink
Passing the timeout as a positional argument is deprecated, it should…
Browse files Browse the repository at this point in the history
… be passed as a keyword argument
  • Loading branch information
guilleiguaran committed Apr 15, 2023
1 parent 5d9a751 commit 99bbe17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
32 changes: 12 additions & 20 deletions lib/redis/connection/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -781,28 +781,28 @@ def persist(key)
def hset(key, *fields)
fields = fields.first if fields.size == 1 && fields.first.is_a?(Hash)
raise_argument_error('hset') if fields.empty?

is_list_of_arrays = fields.all?{|field| field.instance_of?(Array)}

raise_argument_error('hmset') if fields.size.odd? and !is_list_of_arrays
raise_argument_error('hmset') if is_list_of_arrays and !fields.all?{|field| field.length == 2}

data_type_check(key, Hash)
insert_count = 0
data[key] ||= {}

if fields.is_a?(Hash)
insert_count = fields.keys.size - (data[key].keys & fields.keys).size

data[key].merge!(fields)
else
fields.each_slice(2) do |field|
insert_count += 1 if data[key][field[0].to_s].nil?

data[key][field[0].to_s] = field[1].to_s
end
end

insert_count
end

Expand Down Expand Up @@ -1156,12 +1156,12 @@ def zpopmin(key, count = nil)
count.nil? ? results.first : results.flatten
end

def bzpopmax(*args)
bzpop(:bzpopmax, args)
def bzpopmax(*args, timeout: 0)
bzpop(:bzpopmax, args, timeout)
end

def bzpopmin(*args)
bzpop(:bzpopmin, args)
def bzpopmin(*args, timeout: 0)
bzpop(:bzpopmin, args, timeout)
end

def zcard(key)
Expand Down Expand Up @@ -1600,15 +1600,7 @@ def srandmember_multiple(key, number)
end
end

def bzpop(command, args)
timeout =
if args.last.is_a?(Hash)
args.pop[:timeout]
elsif args.last.respond_to?(:to_int)
args.pop.to_int
end

timeout ||= 0
def bzpop(command, args, timeout)
single_pop_command = command.to_s[1..-1]
keys = args.flatten
keys.each do |key|
Expand Down
4 changes: 2 additions & 2 deletions spec/sorted_sets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ module FakeRedis
it "should pop members with the highest score from first sorted set that is non-empty" do
@client.zadd("key1", [1, "val1", 2, "val2"])
@client.zadd("key2", [3, "val3"])
expect(@client.bzpopmax("nonexistent", "key1", "key2", 0)).to eq(["key1", "val2", 2.0])
expect(@client.bzpopmax("nonexistent", "key1", "key2", timeout: 0)).to eq(["key1", "val2", 2.0])
expect(@client.bzpopmax("nonexistent")).to eq(nil)
end

it "should pop members with the lowest score from first sorted set that is non-empty" do
@client.zadd("key1", [1, "val1", 2, "val2"])
@client.zadd("key2", [3, "val3"])
expect(@client.bzpopmin("nonexistent", "key1", "key2", 0)).to eq(["key1", "val1", 1.0])
expect(@client.bzpopmin("nonexistent", "key1", "key2", timeout: 0)).to eq(["key1", "val1", 1.0])
expect(@client.bzpopmin("nonexistent")).to eq(nil)
end

Expand Down

0 comments on commit 99bbe17

Please sign in to comment.