KeyDB icon indicating copy to clipboard operation
KeyDB copied to clipboard

[NEW] Support for combining NX and GET flags on SET command - Upgrade to Redis version > 7.0.0

Open anp13 opened this issue 3 years ago • 0 comments

The problem/use-case that the feature addresses

One should be able to set a key/value if the key does not already exist and get an appropriate response to indicate if the key was stored or not. Currently we can use SET NX to set a key/value if the key does not already exist but there is no way to know if the key was actually stored or not.

Another option is using the SETNX command. The response from the SETNX command indicates if the item was stored or not (true or false), but it does not accept expiry time as an input like the SET command does. Also the SETNX command is on a path of deprecation in Redis.

Description of the feature

If the key exists the SET command should return the old value and avoid setting it, and if it does't exist it should return nil and set the new key/value with expiry time. Redis supports this using the NX and GET flags together on the SET command : https://redis.io/commands/set/. Here is the PR which implemented this: https://github.com/redis/redis/pull/8906 . KeyDB must use Redis version > 7.0.0 to support this feature.

Alternatives you've considered

I tried using the SETNX command as its response indicates if the item was stored or not (true or false), but it does not accept expiry time as an input.

anp13 avatar May 11 '22 19:05 anp13