Skip to content

Commit

Permalink
Fail msetnx if passed arguments are empty (#152)
Browse files Browse the repository at this point in the history
Resolves #151
  • Loading branch information
tildedave authored and Stephen Kwong committed Sep 5, 2018
1 parent 99fc1af commit fd4e311
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mockredis/client.py
Expand Up @@ -434,6 +434,9 @@ def msetnx(self, *args, **kwargs):
else:
mapping = kwargs

if len(mapping) == 0:
raise ResponseError("wrong number of arguments for 'msetnx' command")

for key in mapping.keys():
if self._encode(key) in self.redis:
return False
Expand Down
4 changes: 4 additions & 0 deletions mockredis/tests/test_string.py
Expand Up @@ -228,6 +228,10 @@ def test_msetnx(self):
ok_(not self.redis.msetnx(**{"key3": "world", "key2": "there"}))
eq_([b"hello", b"there", None], self.redis.mget("key1", "key2", "key3"))

@raises_response_error
def test_msetnx_empty_args(self):
self.redis.msetnx({})

def test_psetex(self):
test_cases = [200, timedelta(milliseconds=250)]
for case in test_cases:
Expand Down

0 comments on commit fd4e311

Please sign in to comment.