Redis INCR concurrency

 

Questions


I am using Redis’ INCR to generate an ID for objects. And then use ZADD to add the object using the ID as key.

Do I need to worry about if there are multiple connections executing this same block of code? Say after id:12 if two connections connect at the same time and both add object using id:13, then one of them would be lost.

 

 

————————————————-

Answer

Since redis is single threaded, this can never happen – only one client can make a change to the database at a time.

block,blocking,concurrency,redis

Leave a Reply

Your email address will not be published. Required fields are marked *