Skip to main content
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

str
required
The key of the hash.
str
A single field name to set. Use with value parameter.
Any
A single value to set. Use with field parameter.
Dict[str, Any]
A dictionary of fields and their values to set. Either use field/value or values, but not both.
bool
Only set fields if the hash does not exist.
bool
Only set fields if the hash already exists.
int
Set expiration time in seconds.
int
Set expiration time in milliseconds.
int
Set expiration as Unix timestamp in seconds.
int
Set expiration as Unix timestamp in milliseconds.
bool
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.

Response

0 if no fields were set, 1 if all the fields were set.

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