Skip to content

Commit

Permalink
hset was not accepting hashes as a parameter (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
secos committed May 1, 2021
1 parent 1b3e9b1 commit 04ab75d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mock_redis/hash_methods.rb
Expand Up @@ -131,6 +131,10 @@ def hscan_each(key, opts = {}, &block)
def hset(key, *args)
added = 0
with_hash_at(key) do |hash|
if args.length == 1 && args[0].is_a?(Hash)
args = args[0].to_a.flatten
end

args.each_slice(2) do |field, value|
added += 1 unless hash.key?(field.to_s)
hash[field.to_s] = value.to_s
Expand Down
4 changes: 4 additions & 0 deletions spec/commands/hset_spec.rb
Expand Up @@ -34,5 +34,9 @@
@redises.hget(@key, '1').should == 'one'
end

it 'stores fields sent in a hash' do
@redises.hset(@key, {'k1' => 'v1', 'k2' => 'v2'}).should == 2
end

it_should_behave_like 'a hash-only command'
end

0 comments on commit 04ab75d

Please sign in to comment.