Skip to content
Closed
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
6 changes: 3 additions & 3 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3034,14 +3034,14 @@ def hlen(self, name):
def hset(self, name, key=None, value=None, mapping=None):
"""
Set ``key`` to ``value`` within hash ``name``,
Use ``mappings`` keyword args to set multiple key/value pairs
Use ``mapping`` keyword args to set multiple key/value pairs
for a hash ``name``.
Returns the number of fields that were added.
"""
if not key and not mapping:
if key is None and not mapping:
raise DataError("'hset' with no key value pairs")
items = []
if key:
if key is not None:
items.extend((key, value))
if mapping:
for pair in mapping.items():
Expand Down
4 changes: 4 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,10 @@ def test_hget_and_hset(self, r):
# key inside of hash that doesn't exist returns null value
assert r.hget('a', 'b') is None

# keys with bool(key) == False
assert r.hset('a', 0, 10) == 1
assert r.hset('a', '', 10) == 1

def test_hset_with_multi_key_values(self, r):
r.hset('a', mapping={'1': 1, '2': 2, '3': 3})
assert r.hget('a', '1') == b'1'
Expand Down