Redis INCR并发

问题描述:

我使用Redis的 INCR 为对象生成ID。然后使用 ZADD 使用ID作为键添加对象。

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

我需要担心,如果有是多个连接执行同一个代码块?如果两个连接同时连接,并且使用 id:13 添加对象,则 id:12

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.

由于redis是单线程的,因此这种情况永远不会发生 - 只有一个客户端可以更改数据库。

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