Use HGETEX to read hash fields and change their expiration in the same call.
Without an expiration option it simply returns the values, like HMGET. EX, PX, EXAT, and PXAT give every requested field a new lifetime or deadline, and PERSIST removes the expiration so the fields stop expiring altogether.
Doing both in one command is what makes sliding expirations possible per field: reading a session attribute can extend it, with no window in which another client sees the field without its refreshed lifetime. FIELDS <numfields> introduces the field list and the count must match.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
(EX <seconds> | PX <milliseconds> | EXAT <unix-time-seconds> | PXAT <unix-time-milliseconds> | PERSIST) | No | No | Choose one form: EX (set a lifetime in seconds); PX (set a lifetime in milliseconds); EXAT (expire at a Unix timestamp in seconds); PXAT (expire at a Unix timestamp in milliseconds); PERSIST (remove the expiration). Left unchanged when omitted. |
FIELDS <numfields> <field> [<field> ...] | Yes | No | Fields to target. Give the field count first, then that many field names. |
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Array of bulk-string values or null values, one per field |
| RESP3 | Array of bulk-string values or null values, one per field |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.