There are several ways to return a key’s expiry in Redis. The method used depends on how we want the expiry to be returned.
We can use the TTL command to return the timeout in seconds. We can alternatively use the PTTL command to return it in milliseconds. Another way to do it is to use the EXPIRETIME which returns the absolute Unix timestamp of the key in seconds, or the PEXPIRETIME command which returns the absolute Unix timestamp of the key in milliseconds.