FIELDEXPIRE

Syntax

  1. FIELDEXPIRE key seconds field [field field ...]

Time complexity: O(N) where N is the number of arguments to the command

ACL categories: @write, @set, @hash, @fast

Set an expiration (TTL or time to live) on one or more fields of a given hash or set key. You must specify at least one field. Field(s) or member(s) will automatically be deleted from the hash or set key when their TTLs expire.

Return

Array reply:

  • Integer reply: -2 if no such field exists in the provided hash or set key, or the provided key does not exist.
  • Integer reply: 1 if the expiration time was set/updated.
  • Integer reply: 2 when FIELDEXPIRE is called with 0 seconds.

Simple error reply:

  • If parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range, an error is returned.
  • If the provided key exists but is neither a hash nor a set, an error is returned.

Examples

  1. dragonfly$> FIELDEXPIRE no-key 20 field1 field2
  2. (nil)
  3. dragonfly$> HSET mykey field1 "hello" field2 "world"
  4. (integer 2)
  5. dragonfly$> FIELDEXPIRE mykey 10 field1 field2 field3
  6. 1) (integer) 1
  7. 2) (integer) 1
  8. 3) (integer) -2
  9. dragonfly$> HGETALL mykey
  10. (empty array)