Upstash Documentation

HSETEX

Set hash fields with expiration support.
2 min read

The HSETEX command sets the specified fields with their values and optionally sets their expiration time or TTL. It supports conditional operations to control when fields should be set.

Arguments#

keystringrequired#

The key of the hash.

optionsobject#

Options for conditional setting and expiration.

Show properties
conditional'FNX' | 'fnx' | 'FXX' | 'fxx'#

Conditional setting options (case-insensitive):

  • FNX: Only set fields if the hash does not exist
  • FXX: Only set fields if the hash already exists
expirationobject#

Expiration options for the hash.

Show expiration
exnumber#

Set expiration time in seconds.

pxnumber#

Set expiration time in milliseconds.

exatnumber#

Set expiration as Unix timestamp in seconds.

pxatnumber#

Set expiration as Unix timestamp in milliseconds.

keepttltrue#

Retain the existing time to live (TTL) associated with the hash key when setting fields. If the hash has an expiration, it will be preserved. Set to true to enable.

fields{ [fieldName]: TValue }required#

An object of fields and their values to set.

Response#

Use Cases#

  • Session Management: Create sessions with automatic expiration
  • Cache with TTL: Store cached data that expires automatically
  • Temporary Data: Create temporary records with built-in cleanup
  • Rate Limiting: Store rate limit counters with automatic reset
  • Conditional Updates: Ensure data consistency with FNX/FXX options