What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

PSETEX

Sets both string value and expiration time in milliseconds of a key. The key is created if it doesn't exist.

Usage
PSETEX key milliseconds value
Complexity
O(1)
Since
2.6.0
ACL Categories
@slow, @string, @write
Command flags
WRITE, DENYOOM

PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

Alternative

SET with the PX argument.

Examples

127.0.0.1:6379> PSETEX mykey 1000 "Hello"
OK
127.0.0.1:6379> PTTL mykey
(integer) 990
127.0.0.1:6379> GET mykey
"Hello"

Replies

RESP2

RESP3