Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hset was not accepting hashes as a parameter #208

Merged
merged 1 commit into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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