4 Ways to Set a Key and its Expiry in Redis

Redis provides us with quite a few options for setting keys and any timeouts associated with those keys. Sometimes we can do it with a single command, other times we need two commands.

Here are four ways to set a key and its expiry in Redis.

Read more

Set an Expiry on an Existing Key in Redis, But Only When the Key Already Has an Expiry

When setting a timeout for a key in Redis, we have the option of setting it only if the key already has an expiry. So, if the key doesn’t already have an associated timeout, the new timeout won’t apply. The new timeout will only apply if the key already has an existing timeout. In such cases the expiry will be reset to the new expiry.

We can do this with the XX option of the EXPIRE command. We can also use the XX option on commands such as EXPIREAT, PEXPIRE, and PEXPIREAT.

Read more

4 Ways to Increment a Key in Redis

In Redis, we have several options for incrementing a key. For example, if we set a key to 1, we can increment it by 1 to make 2. Or we can increment it by whatever amount we desire.

Below are four ways to increment a key in Redis.

Read more