What is PEXPIREAT in Redis? How to set the expiration time of a key in Redis based on a Unix timestamp in milliseconds?
PEXPIREAT
is a Redis command that allows you to set the expiration time of a key in Redis based on a Unix timestamp in milliseconds. The command works similarly to EXPIREAT
, which sets the expiration time of a key based on a Unix timestamp in seconds, but with PEXPIREAT
you can set the time-to-live of a key in milliseconds.
The syntax of the PEXPIREAT
command is as follows:
PEXPIREAT key milliseconds-timestamp
where key
is the name of the key and milliseconds-timestamp
is the Unix timestamp in milliseconds until the key expires.
For example, to set the key mykey
to expire at Unix timestamp 1649361600000
(which corresponds to 2022-04-07 00:00:00
in UTC time), you can run:
PEXPIREAT mykey 1649361600000
This command sets the expiration time of the key mykey
based on the specified Unix timestamp in milliseconds.
Note that PEXPIREAT
is available since Redis version 2.6.0, so make sure your Redis version supports it before using this command.
Comments
Post a Comment