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

HMSET should fail on empty mapping. #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mockredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ def hlen(self, hashkey):

def hmset(self, hashkey, value):
"""Emulate hmset."""
if len(value) == 0:
raise ResponseError("empty mapping passed to 'hmset'")

redis_hash = self._get_hash(hashkey, 'HMSET', create=True)
for key, value in value.items():
Expand Down
6 changes: 5 additions & 1 deletion mockredis/tests/test_hash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nose.tools import eq_, ok_

from mockredis.tests.fixtures import setup, teardown
from mockredis.tests.fixtures import raises_response_error, setup, teardown


class TestRedisHash(object):
Expand Down Expand Up @@ -72,6 +72,10 @@ def test_hmset(self):
eq_(b"value1", self.redis.hget(hashkey, "key1"))
eq_(b"value2", self.redis.hget(hashkey, "key2"))

@raises_response_error
def test_hmset_empty(self):
self.redis.hmset("hash", {})

def test_hmset_integral(self):
hashkey = "hash"
self.redis.hmset(hashkey, {1: 2, 3: 4})
Expand Down