Redis INCR and multiple processes?
I used PostgreSQL sequencing SELECT nextval('number');
to make sure I get a new number even if there are multiple clients, since it is nextval
guaranteed to return crisp and incremental values.
I wanted to use the same mechanism with Redis. I thought using a command INCR
, but I want to make sure I understand well that it will give the same guarantee as the command nextval
? Is there no risk of getting the same number if multiple processes are executing this command or do I need to use Redis locking?
thank
source to share
Redis is a single threaded engine, so the execution of all commands is serialized. It always provides atomicity and isolation (in the ACID sense) for each individual command.
The consequence is that one INCR command is used and its result is safe (even if several connections do it at the same time).
source to share