skip to Main Content

I want to generate a unique id in my application . Is it ok to use redis auto increment id for this purpose ? Will it be a unique id even when in a cluster ?

2

Answers


  1. yes, as the INCR documentation states it is an atomic operation and thus provides this guarantee

    Login or Signup to reply.
  2. Redis can do id generation based on INCR command but may not be a good solution.

    As Redis will not guarantee ACID for update(INCR), it may lose it consistency when Redis restart of failover. Both RDB and AOF are doing persistence in async way and data can be lost. For ID generator, it may generate duplicate IDs after restart(or failover in Cluster/Sentinel.

    In your case if you don’t care this scenario, or you think manual recovery is acceptable, you can use Redis as generator since it fast enough for most case(compare with MySQL or other database).

    Or there are still some useful ID generation algorithm like SnowFlake which will guarantee the global incremental and no duplicate exists.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search