I have a quick question to people who are more familiar with Redis internals and perhaps know the answer.
I use socket.io and have a map of sessionID - socket(s) stored. In addition to that I use SET command to store empty value to indicate user is connected (if no sockets are associated with sessionID). To account for page reloads the DEL command is executed with a timeout. This leads to situation where I have no active sockets, but the online status is still set in Redis.
This means if user use a single tab, every page reload means the SET command is executed. What I am wondering is whether SETNX would be more performant here? Basically, would the check performed by SETNX be faster than setting the value again with SET? Assuming that the value will exist in 99.99% of cases.
My guess is that it should be faster, but perhaps there's something I don't know. So could anyone confirm my guess or explain me why SET may still be faster?
via user1970395
No comments:
Post a Comment