Reputation: 3615
I'm writting this application in which i will use Redis as a database of sorts to store chat messages. I am considering using SETNX whenever i need to set any given key just to be sure it doesn't already exist.
But The application needs to be very responsive since it it real time. What i want to know is whether performing the SETNX operation is costly, especially if there are a large number of clients performing that operation.
NB: I read through this document http://redis.io/topics/data-types-intro and it looks like quit a bit is going on in the SETNX implementation, however i still am not sure how costly it could be. Thanks.
Upvotes: 1
Views: 1155
Reputation: 68453
What i want to know is whether performing the SETNX operation is costly, especially if there are a large number of clients performing that operation.
Regarding the speed - since redis is memory based it will be "very fast". Definitely faster than case where you would first try to get the key in order to figure out if it exists and set the key if it doesn't since you would be performing two network roundtrips (get and set) instead of one (setnx).
Regarding the large number of clients - redis is single threaded and executes commands sequentialy as they arrive and it's capable of handling many simultaneously connected clients (see docs).
Upvotes: 1