Hash
HEXPIRE
Set a timeout on a hash field in seconds.
Arguments
keybodystrrequired
The key of the hash.
fieldsbodyUnion[str, List[str]]required
The field or list of fields within the hash to set the expiry for.
secondsbodyUnion[int, datetime.timedelta]required
The timeout in seconds as an integer or a datetime.timedelta object.
nxbodybool
Set expiry only when the field has no expiry. Defaults to False.
xxbodybool
Set expiry only when the field has an existing expiry. Defaults to False.
gtbodybool
Set expiry only when the new expiry is greater than the current one. Defaults to False.
ltbodybool
Set expiry only when the new expiry is less than the current one. Defaults to False.
Response
List[int]required
A list of integers indicating whether the expiry was successfully set.
-2if the field does not exist in the hash or if key doesn't exist.0if the expiration was not set due to the condition.1if the expiration was successfully set.2if called with 0 seconds/milliseconds or a past Unix time.
For more details, see HEXPIRE documentation.
Example
redis.hset(hash_name, field, value)assert redis.hexpire(hash_name, field, 1) == [1]