Description
Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.Syntax
Parameters
string
required
The key to set
TData
required
The value to store. Can be a string, number, object, or any serializable data
SetCommandOptions
Optional configuration for the SET command
Type Parameters
type
The type of the value being stored
Returns
TData | 'OK' | null
- Returns
"OK"if SET was executed correctly - Returns
nullif the SET operation was not performed (due tonxorxxconditions) - Returns the old value if the
getoption was specified
Examples
Basic Usage
Set with Expiration
Conditional Set
Set and Get Old Value
Working with Objects
Keep TTL
Notes
- The
ex,px,exat,pxat, andkeepTtloptions are mutually exclusive - The
nxandxxoptions are mutually exclusive - When using the
getoption, the command returns the old value instead of"OK"