HEXPIRE

Since 1.1.0Hashes

Syntax

HEXPIRE key seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
  • Flags: write
  • ACL categories: @hash, @slow, @write
  • Arity: -6

Makes fields of the hash at key expire after seconds. When a field expires, it is removed from the hash; a hash left with no fields is deleted. numfields is how many fields follow.

Options

OptionSet the expiry only if
NXthe field has none
XXthe field has one
GTthe new expiry is later than the current one
LTthe new expiry is earlier than the current one

Reply

An array with one element per field:

  • 1: the expiry was set;
  • 0: the condition was not met;
  • 2: the time was zero or in the past, and the field was deleted;
  • -2: no such field, or no such key.

Examples

> HSET s token abc user ada
(integer) 2
> HEXPIRE s 100 FIELDS 2 token nope
1) (integer) 1
2) (integer) -2
> HEXPIRE s 50 GT FIELDS 1 token
1) (integer) 0
> HEXPIRE s 0 FIELDS 1 token
1) (integer) 2
> HGETALL s
1) "user"
2) "ada"