From fc146dece8d114dc5680be4c68c64b71cdfa8c4f Mon Sep 17 00:00:00 2001 From: Marek Czaplicki Date: Tue, 22 Feb 2022 14:36:22 +0100 Subject: [PATCH 1/5] Allow passing `items` to `hset` --- aioredis/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aioredis/client.py b/aioredis/client.py index 9b4e1a3d3..2c33cd9f6 100644 --- a/aioredis/client.py +++ b/aioredis/client.py @@ -3497,16 +3497,19 @@ def hset( key: Optional[FieldT] = None, value: Optional[EncodableT] = None, mapping: Optional[Mapping[AnyFieldT, EncodableT]] = None, + items: Optional[List[Union[FieldT, Optional[EncodableT]]]] = None, ) -> Awaitable: """ Set ``key`` to ``value`` within hash ``name``, - ``mapping`` accepts a dict of key/value pairs that that will be + ``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. """ - 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: List[Union[FieldT, Optional[EncodableT]]] = [] + items: List[Union[FieldT, Optional[EncodableT]]] = items or [] if key is not None: items.extend((key, value)) if mapping: From ec11c3f229b8cb4c31c96d88dba449b0f12f2146 Mon Sep 17 00:00:00 2001 From: Marek Czaplicki Date: Tue, 22 Feb 2022 14:38:51 +0100 Subject: [PATCH 2/5] Add test for `hset` with `items` --- tests/test_commands.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 51ab80738..15c13c3fa 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1809,6 +1809,17 @@ async def test_hset_with_multi_key_values(self, r: aioredis.Redis): assert await r.hget("b", "1") == b"1" assert await r.hget("b", "2") == b"2" assert await r.hget("b", "foo") == b"bar" + + async def test_hset_with_items(self, r: aioredis.Redis): + await r.hset("a", items=["1", 1, "2", 2, "3", 3] + assert await r.hget("a", "1") == b"1" + assert await r.hget("a", "2") == b"2" + assert await r.hget("a", "3") == b"3" + + await r.hset("b", "foo", "bar", items=["1", 1, "2", 2]) + assert await r.hget("b", "1") == b"1" + assert await r.hget("b", "2") == b"2" + assert await r.hget("b", "foo") == b"bar" async def test_hset_without_data(self, r: aioredis.Redis): with pytest.raises(exceptions.DataError): From 70af52e431c3dc043e4c353eee46be7aec1bfb7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:41:08 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 15c13c3fa..5070f900a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1809,7 +1809,7 @@ async def test_hset_with_multi_key_values(self, r: aioredis.Redis): assert await r.hget("b", "1") == b"1" assert await r.hget("b", "2") == b"2" assert await r.hget("b", "foo") == b"bar" - + async def test_hset_with_items(self, r: aioredis.Redis): await r.hset("a", items=["1", 1, "2", 2, "3", 3] assert await r.hget("a", "1") == b"1" From 3a2d06a255737615b4523a57df2c9b64f50bc34a Mon Sep 17 00:00:00 2001 From: Marek Czaplicki Date: Tue, 22 Feb 2022 14:41:16 +0100 Subject: [PATCH 4/5] Update CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 36953225a..88d12d0ed 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -42,6 +42,7 @@ Kyrylo Dehtyarenko Leonid Shvechikov Maksim Novikov Manuel Miranda +Marek Czaplicki Marek Szapiel Marijn Giesen Martin From 789c72b01562207c906f7f49747b981effd4e634 Mon Sep 17 00:00:00 2001 From: Marek Czaplicki Date: Tue, 22 Feb 2022 14:42:54 +0100 Subject: [PATCH 5/5] Create 1299.feature --- CHANGES/1299.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/1299.feature diff --git a/CHANGES/1299.feature b/CHANGES/1299.feature new file mode 100644 index 000000000..e224a73da --- /dev/null +++ b/CHANGES/1299.feature @@ -0,0 +1 @@ +Allow passing `items` to `hset`.