HGETEX
Syntax
HGETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] FIELDS numfields field [field ...]
- Available since:
- Redis CE 8.0.0
- Time complexity:
- O(N) where N is the number of specified fields
- ACL categories:
-
@write
,@hash
,@fast
,
Get the value of one or more fields of a given hash key and optionally set their expiration time or time-to-live (TTL).
Options
The HGETEX
command supports a set of options:
EX seconds
-- Set the specified expiration time, in seconds.PX milliseconds
-- Set the specified expiration time, in milliseconds.EXAT unix-time-seconds
-- Set the specified Unix time at which the fields will expire, in seconds.PXAT unix-time-milliseconds
-- Set the specified Unix time at which the fields will expire, in milliseconds.PERSIST
-- Remove the TTL associated with the fields.
The EX
, PX
, EXAT
, PXAT
, and PERSIST
options are mutually exclusive.
Example
redis> HSET mykey field1 "Hello" field2 "World"
(integer) 2
redis> HGETEX mykey EX 120 FIELDS 1 field1
1) "Hello"
redis> HGETEX mykey EX 100 FIELDS 1 field2
1) "World"
redis> HTTL mykey FIELDS 2 field1 field2
1) (integer) 91
2) (integer) 85
redis> HTTL mykey FIELDS 3 field1 field2 field3
1) (integer) 75
2) (integer) 68
3) (integer) -2
...
redis> HTTL mykey FIELDS 3 field1 field2
1) (integer) -2
2) (integer) -2
redis> HGETALL mykey
(empty array)
RESP2/RESP3 Reply
- Array reply. For each field:
- Integer reply:
-2
if no such field exists in the provided hash key, or the provided key does not exist, or if the field exists but has no associated expiration set. - Integer reply: the expiration in seconds.
- Integer reply: