Set an Expiry on an Existing Redis Key Only When the Key Doesn’t Already Have an Expiry

When setting an expiry for an existing key in Redis, we now have the option to set the expiry only if the key doesn’t already have an expiry. That’s because Redis 7.0.0 introduced some new options that allows us to do this and other things.

In this case, we can use the NX option when setting the expiry to specify that the expiry should only be set if the key doesn’t already have an expiry. We can use this option on commands such as EXPIRE, EXPIREAT, PEXPIRE, and PEXPIREAT.

Continue reading