diff options
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/redis/client.py b/redis/client.py index dde701f..8ebcece 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2996,12 +2996,23 @@ class Redis(object): "Return the number of elements in hash ``name``" return self.execute_command('HLEN', name) - def hset(self, name, key, value): + def hset(self, name, key=None, value=None, mapping=None): """ - Set ``key`` to ``value`` within hash ``name`` - Returns 1 if HSET created a new field, otherwise 0 + Set ``key`` to ``value`` within hash ``name``, + Use ``mappings`` keyword args to set multiple key/value pairs + for a hash ``name``. + Returns the number of fields that were added. """ - return self.execute_command('HSET', name, key, value) + if not key and not mapping: + raise DataError("'hset' with no key value pairs") + items = [] + if key: + items.extend((key, value)) + if mapping: + for pair in mapping.items(): + items.extend(pair) + + return self.execute_command('HSET', name, *items) def hsetnx(self, name, key, value): """ @@ -3015,6 +3026,7 @@ class Redis(object): Set key to value within hash ``name`` for each corresponding key and value from the ``mapping`` dict. """ + warnings.warn(DeprecationWarning('Use hset')) if not mapping: raise DataError("'hmset' with 'mapping' of length 0") items = [] |