I plan to use redis as an unique atomic id generator. However, my concern there might be simulatoneous web requests from multiple browsers. I was wondering, what is the common practice to make the following operations atomic?
get id from redis
if id is not found
insert id as 0 into redis
else
store the id in a variable
increase id by one
store the new id back to redis
If I were in desktop app or mobile app, I would use synchronized
keyword in Java to avoid race condition.
However, how about for a PHP web app?