summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Czaplicki <mdczaplicki@gmail.com>2022-03-06 13:29:01 +0100
committerGitHub <noreply@github.com>2022-03-06 14:29:01 +0200
commit6c798df564b644bdad1d7e09f1d750e4fee34848 (patch)
treef666b6c462a510b5c78c4922277361a2e68fd10e
parent98fd06eb8df1ecc109b4a5fb2d2a2e810142283e (diff)
downloadredis-py-6c798df564b644bdad1d7e09f1d750e4fee34848.tar.gz
Add support for HSET items (#2006)
* Add `items` parameter to `hset` * Add test for `hset` with `items` * Update CHANGES * fix test_profile Co-authored-by: Chayim <chayim@users.noreply.github.com> Co-authored-by: dvora-h <dvora.heller@redis.com>
-rw-r--r--CHANGES3
-rw-r--r--redis/commands/core.py7
-rw-r--r--tests/test_commands.py11
-rw-r--r--tests/test_search.py2
4 files changed, 20 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index ddf7cfd..ca2d2e8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
+
+ * Add `items` parameter to `hset` signature
* Create codeql-analysis.yml (#1988). Thanks @chayim
* Add limited support for Lua scripting with RedisCluster
* Implement `.lock()` method on RedisCluster
+
* 4.1.3 (Feb 8, 2022)
* Fix flushdb and flushall (#1926)
* Add redis5 and redis4 dockers (#1871)
diff --git a/redis/commands/core.py b/redis/commands/core.py
index 2937780..457b5c8 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -4589,18 +4589,21 @@ class HashCommands(CommandsProtocol):
key: Optional[str] = None,
value: Optional[str] = None,
mapping: Optional[dict] = None,
+ items: Optional[list] = None,
) -> Union[Awaitable[int], int]:
"""
Set ``key`` to ``value`` within hash ``name``,
``mapping`` accepts a dict of key/value pairs that will be
added to hash ``name``.
+ ``items`` accepts a list of key/value pairs that will be
+ added to hash ``name``.
Returns the number of fields that were added.
For more information check https://redis.io/commands/hset
"""
- if key is None and not mapping:
+ if key is None and not mapping and not items:
raise DataError("'hset' with no key value pairs")
- items = []
+ items = items or []
if key is not None:
items.extend((key, value))
if mapping:
diff --git a/tests/test_commands.py b/tests/test_commands.py
index dc10cde..46303e5 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -2546,6 +2546,17 @@ class TestRedisCommands:
assert r.hget("b", "2") == b"2"
assert r.hget("b", "foo") == b"bar"
+ def test_hset_with_key_values_passed_as_list(self, r):
+ r.hset("a", items=["1", 1, "2", 2, "3", 3])
+ assert r.hget("a", "1") == b"1"
+ assert r.hget("a", "2") == b"2"
+ assert r.hget("a", "3") == b"3"
+
+ r.hset("b", "foo", "bar", items=["1", 1, "2", 2])
+ assert r.hget("b", "1") == b"1"
+ assert r.hget("b", "2") == b"2"
+ assert r.hget("b", "foo") == b"bar"
+
def test_hset_without_data(self, r):
with pytest.raises(exceptions.DataError):
r.hset("x")
diff --git a/tests/test_search.py b/tests/test_search.py
index 88d57a9..5eb8e97 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -1500,7 +1500,7 @@ def test_profile(client):
res, det = client.ft().profile(req)
assert det["Iterators profile"]["Counter"] == 2.0
assert det["Iterators profile"]["Type"] == "WILDCARD"
- assert det["Parsing time"] < 0.5
+ assert isinstance(det["Parsing time"], float)
assert len(res.rows) == 2 # check also the search result