Redis INCR并发 [英] Redis INCR concurrency

查看:702
本文介绍了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.

这篇关于Redis INCR并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆