diff --git a/lib/mock_redis/hash_methods.rb b/lib/mock_redis/hash_methods.rb index 688976d..9239830 100644 --- a/lib/mock_redis/hash_methods.rb +++ b/lib/mock_redis/hash_methods.rb @@ -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 diff --git a/spec/commands/hset_spec.rb b/spec/commands/hset_spec.rb index 7266ba9..18eab77 100644 --- a/spec/commands/hset_spec.rb +++ b/spec/commands/hset_spec.rb @@ -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