Skip to main content
Prefer SET with the PX argument in new code: SET <key> <value> PX <milliseconds>.
Use PSETEX to set a value together with a lifetime in milliseconds. The value and the expiration are applied in the same atomic step, so the key never exists without its expiration, which is the point of the command: setting the value and then expiring it separately leaves a window where a crash makes the key permanent. A lifetime of zero or less returns an error. It is the millisecond form of SETEX, and SET with the PX option is the more flexible way to write the same thing.

Syntax

Arguments

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Related topics

HSETEXHGETEX