summaryrefslogtreecommitdiff
path: root/redis/utils.py
diff options
context:
space:
mode:
authorChayim I. Kirshen <c@kirshen.com>2021-11-29 20:07:20 +0200
committerChayim I. Kirshen <c@kirshen.com>2021-11-29 20:07:20 +0200
commit39fc550251d238cdba7966ff153321ca9e488508 (patch)
treee79360ec70feac7f0ab992813f8b2d43f7c67bab /redis/utils.py
parenta924269502b96dc71339cca3dfb20aaa3899a9d0 (diff)
parent4db85ef574a64a2b230a3ae1ff19c9d04065a114 (diff)
downloadredis-py-39fc550251d238cdba7966ff153321ca9e488508.tar.gz
merging masterck-linkdocs
Diffstat (limited to 'redis/utils.py')
-rw-r--r--redis/utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/redis/utils.py b/redis/utils.py
index 26fb002..0e78cc5 100644
--- a/redis/utils.py
+++ b/redis/utils.py
@@ -36,3 +36,39 @@ def str_if_bytes(value):
def safe_str(value):
return str(str_if_bytes(value))
+
+
+def dict_merge(*dicts):
+ """
+ Merge all provided dicts into 1 dict.
+ *dicts : `dict`
+ dictionaries to merge
+ """
+ merged = {}
+
+ for d in dicts:
+ merged.update(d)
+
+ return merged
+
+
+def list_keys_to_dict(key_list, callback):
+ return dict.fromkeys(key_list, callback)
+
+
+def merge_result(command, res):
+ """
+ Merge all items in `res` into a list.
+
+ This command is used when sending a command to multiple nodes
+ and they result from each node should be merged into a single list.
+
+ res : 'dict'
+ """
+ result = set()
+
+ for v in res.values():
+ for value in v:
+ result.add(value)
+
+ return list(result)