Skip to content

Commit

Permalink
Add HPERSIST command
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Dec 3, 2024
1 parent fa6242d commit 56d62c4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
15 changes: 15 additions & 0 deletions coredis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,21 @@ async def hpexpireat(
CommandName.HPEXPIREAT, *pieces, callback=TupleCallback[int]()
)

@versionadded(version="4.18.0")
@redis_command(
CommandName.HPERSIST, version_introduced="7.4.0", group=CommandGroup.HASH
)
async def hpersist(self, key: KeyT, fields: Parameters[StringT]) -> Tuple[int, ...]:
"""
Removes the expiration time for each specified field
"""
pieces: CommandArgList = [key, PrefixToken.FIELDS, len(list(fields))]
pieces.extend(fields)

return await self.execute_command(
CommandName.HPERSIST, *pieces, callback=TupleCallback[int]()
)

@redis_command(
CommandName.HGET,
group=CommandGroup.HASH,
Expand Down
6 changes: 6 additions & 0 deletions coredis/pipeline.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ class Pipeline(ObjectProxy, Generic[AnyStr]): # type: ignore
async def hmset(
self, key: "KeyT", field_values: "Mapping[StringT, ValueT]"
) -> Pipeline[AnyStr]: ...
async def hpersist(
self, key: "KeyT", fields: "Parameters[StringT]"
) -> Pipeline[AnyStr]: ...
async def hpexpire(
self,
key: "KeyT",
Expand Down Expand Up @@ -1406,6 +1409,9 @@ class ClusterPipeline(ObjectProxy, Generic[AnyStr]): # type: ignore
async def hmset(
self, key: "KeyT", field_values: "Mapping[StringT, ValueT]"
) -> ClusterPipeline[AnyStr]: ...
async def hpersist(
self, key: "KeyT", fields: "Parameters[StringT]"
) -> ClusterPipeline[AnyStr]: ...
async def hpexpire(
self,
key: "KeyT",
Expand Down
28 changes: 18 additions & 10 deletions docs/source/compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,24 @@ Sets the values of multiple fields.



HPERSIST
********

Removes the expiration time for each specified field

- Documentation: `HPERSIST <https://redis.io/commands/hpersist>`_
- Implementation: :meth:`~coredis.Redis.hpersist`

- New in redis: 7.4.0



- .. versionadded:: 4.18.0





HPEXPIRE
********

Expand Down Expand Up @@ -1336,16 +1354,6 @@ Returns all values in a hash.



HPERSIST [X]
************

Removes the expiration time for each specified field

- Documentation: `HPERSIST <https://redis.io/commands/hpersist>`_

- Not Implemented





Expand Down
9 changes: 9 additions & 0 deletions tests/commands/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ async def test_hpttl(self, client, _s):
"a", ["1", "2", "5"]
)

@pytest.mark.min_server_version("7.4.0")
async def test_hpersist(self, client, _s):
await client.hset("a", {"1": 1, "2": 2, "3": 3, "4": 4})
assert (-2,) == await client.hpersist("missing", ["1"])
await client.hpexpire("a", 5000, ["1"])
assert (pytest.approx(5000, abs=1000),) == await client.hpttl("a", ["1"])
assert (1,) == await client.hpersist("a", ["1"])
assert (-1,) == await client.hpttl("a", ["1"])

async def test_hgetall(self, client, _s):
h = {_s("a1"): _s("1"), _s("a2"): _s("2"), _s("a3"): _s("3")}
await client.hset("a", h)
Expand Down

0 comments on commit 56d62c4

Please sign in to comment.