The Python-side representaion of Redis hash value. It behaves such as built-in Python dict object. More exactly, it implements collections.MutableMapping protocol.
Redis commands | Hash methods |
---|---|
DEL | Hash.clear() |
HDEL | del (Hash.__delitem__()) |
HEXISTS | in (Hash.__contains__()) |
HGET | Hash.__getitem__(), Hash.get() |
HGETALL | Hash.items() |
HINCRBY | N/A |
HINCRBYFLOAT | N/A |
HKEYS | iter() (Hash.__iter__()), Hash.keys() |
HLEN | len() (Hash.__len__()) |
HMGET | N/A |
HMSET | Hash.update() |
HSET | = (Hash.__setitem__()) |
HSETNX | Hash.setdefault() |
HVALS | Hash.values() |
N/A | Hash.pop() |
N/A | Hash.popitem() |
Tests whether the given key exists.
Parameters: | key – the key |
---|---|
Returns: | True if the key exists or False |
Return type: | bool |
Note
It is directly mapped to Redis HEXISTS command.
Removes the key.
Parameters: | key – the key to delete |
---|---|
Raises: |
|
Note
It is directly mapped to Redis HDEL command.
Gets the value of the given key.
Parameters: | key – the key to get its value |
---|---|
Returns: | the value of the key |
Raises: |
|
Note
It is directly mapped to Redis HGET command.
Iterates over its keys().
Returns: | the iterator which yields its keys |
---|---|
Return type: | collections.Iterator |
Note
It is directly mapped to Redis HKEYS command.
Gets the number of items.
Returns: | the number of items |
---|---|
Return type: | numbers.Integral |
Note
It is directly mapped to Redis HLEN command.
Sets the key with the value.
Parameters: |
|
---|---|
Raises exceptions.TypeError: | |
if the given key is not acceptable by its key_type or the given value is not acceptable by its value_type |
Note
It is directly mapped to Redis HSET command.
Gets its all (key, value) pairs. There isn’t any meaningful order of pairs.
Returns: | the set of (key, value) pairs (tuple) |
---|---|
Return type: | collections.ItemsView |
Note
This method is mapped to Redis HGETALL command.
(sider.types.Bulk) The type of hash keys.
Gets its all keys. Equivalent to __iter__() except it returns a Set instead of iterable. There isn’t any meaningful order of keys.
Returns: | the set of its all keys |
---|---|
Return type: | collections.KeysView |
Note
This method is directly mapped to Redis HKEYS command.
Sets the given default value to the key if it doesn’t exist and then returns the current value of the key.
For example, the following code is:
val = hash.setdefault('key', 'set this if not exist')
equivalent to:
try:
val = hash['key']
except KeyError:
val = hash['key'] = 'set this if not exist'
except setdefault() method is an atomic operation.
Parameters: |
|
---|---|
Raises exceptions.TypeError: | |
when the given key is not acceptable by its key_type or the given default value is not acceptable by its value_type |
Note
This method internally uses Redis HSETNX command which is atomic.
Updates the hash from the given mapping and keyword arguments.
If mapping has keys() method, it does:
for k in mapping:
self[k] = mapping[k]
If mapping lacks keys() method, it does:
for k, v in mapping:
self[k] = v
In either case, this is followed by (where keywords is a dict of keyword arguments):
for k, v in keywords.items():
self[k] = v
Parameters: |
|
---|---|
Raises: |
|
(sider.types.Bulk) The type of hash values.
Gets its all values. It returns a list but there isn’t any meaningful order of values.
Returns: | its all values |
---|---|
Return type: | collections.ValuesView |
Note
This method is directly mapped to Redis HVALS command.