I want to run a HSET
command but only if the key exists. Similar to HSETNX
except exists
instead of not exists
I've read about maybe using WATCH or something but so far I can't really figure it out. I would appreciate a nudge in the right direction. The only thing I see is this but I don't see how this works considering these aren't even valid redis commands.
Also, after reading about WATCH that concerns me because I don't want to abort the transaction if another request comes it.
I'm basically trying to HGETALL and immediately after issue a second command for HSET, saying that it has been read a single time.
After that, I want all subsequent requests to know that it's already been read.
The problem is, when I call HSET on a key that doesn't exist, instead of just failing it creates a new entry in the redis database, which I don't want. I only want it to update records if it exists without having to check if it exists first
According to this, that method won't work anyway for high contention (there will be lots of requests to the key)
https://github.com/antirez/redis/issues/441
It says I could use scripting somehow but I'm not sure