Using the node_redis client, how can I make two commands execute such that they will be performed atomically when the second command relies on the result of the first.
Here is an example of what I am thinking.
client.multi([
["hget", orgId, topicId]
]).exec(function (err, sessions) {
sessions = JSON.parse(sessions);
if (sessions === undefined) {
sessions = [sessionId];
}
else {
sessions.push(sessionId)
}
client.hset(orgId, topicId, JSON.stringify(sessions)]);
});
Can someone confirm there would not be a race condition to write back the new value if this ran simultaneously in two places.