PEXPIRE · Valkey

PEXPIRE

Sets the expiration time of a key in milliseconds.

Usage

PEXPIRE key milliseconds [NX | XX | GT | LT]

Description

This command works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.

Options

The PEXPIRE command supports a set of options

A non-volatile key is treated as an infinite TTL for the purpose of GT and LT. The GT, LT and NX options are mutually exclusive.

Reply

One of the following:

Complexity

O(1)

ACL Categories

@fast @keyspace @write

Examples

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> PEXPIRE mykey 1500
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) 1
127.0.0.1:6379> PTTL mykey
(integer) 1480
127.0.0.1:6379> PEXPIRE mykey 1000 XX
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) 1
127.0.0.1:6379> PEXPIRE mykey 1000 NX
(integer) 0
127.0.0.1:6379> TTL mykey
(integer) 1

History

See also

COPY, DEL, DUMP, EXISTS, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, OBJECT ENCODING, OBJECT FREQ, OBJECT HELP, OBJECT IDLETIME, OBJECT REFCOUNT, PERSIST, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, SCAN, SORT, SORT_RO, TOUCH, TTL, TYPE, UNLINK, WAIT, WAITAOF.