PEXPIRE

PEXPIRE key milliseconds [NX | XX | GT | LT]
Available since:
Redis Open Source 2.6.0
Time complexity:
O(1)
ACL categories:
@keyspace, @write, @fast,
Compatibility:
Redis Software and Redis Cloud compatibility

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

Required arguments

key

The name of the key to set a timeout on.

milliseconds

The timeout, in milliseconds.

Optional arguments

The following options modify the command's behavior. They are mutually exclusive.

NX

Set expiry only when the key has no expiry.

XX

Set expiry only when the key has an existing expiry.

GT

Set expiry only when the new expiry is greater than the current one. A non-volatile key is treated as an infinite TTL for the purpose of GT.

LT

Set expiry only when the new expiry is less than the current one. A non-volatile key is treated as an infinite TTL for the purpose of LT.

Examples

SET mykey "Hello" PEXPIRE mykey 1500 TTL mykey PTTL mykey PEXPIRE mykey 1000 XX TTL mykey PEXPIRE mykey 1000 NX TTL mykey

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Active-Active
✅ Standard
✅ Active-Active

Return information

One of the following:

  • Integer reply: 0 if the timeout was not set. For example, if the key doesn't exist, or the operation skipped because of the provided arguments.
  • Integer reply: 1 if the timeout was set.

History

  • Starting with Redis version 7.0.0: Added options: NX, XX, GT and LT.
RATE THIS PAGE
Back to top ↑