Enter your search


Redis script for an HMSETEX command

We have added an implementation of HMSETEX to our redis-scripts repo. The repo is a collection of scripts packaged up as a module for Node.js to make them easy to use in Node apps. Hope it helps!


Redis’ existence-aware commands are a useful way to atomically modify keys based on their state. For example, SET[XX|NX] is a fast and concurrency-safe way of setting keys only if they exist (XX) or don’t exist (NX).

Not all keys support this option, namely HMSET. HMSET will always create the key to set its fields if it doesn’t exist.

In cases where we only want to modify hash keys that exist (say, our app relies on ttl to clear out keys), it would be convenient to have some kind of HMSETEX so we can perform the check/set logic atomically in a single command. This is much safer and simpler than having to check/set across round trips between your app and Redis, and less prone to concurrency bugs too.

You May Also Like

Group 5 Created with Sketch. Group 11 Created with Sketch. CLOSE ICON Created with Sketch. icon-microphone Group 9 Created with Sketch. CLOSE ICON Created with Sketch. SEARCH ICON Created with Sketch. Group 4 Created with Sketch. Path Created with Sketch. Group 5 Created with Sketch.