V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
imherer
V2EX  ›  程序员

redis 的 LPOP 能保证唯一性(原子性)吗?

  •  
  •   imherer · 2017-09-14 19:57:58 +08:00 · 6047 次点击
    这是一个创建于 2405 天前的主题,其中的信息可能已经有所发展或是发生改变。
    假如多个程序(进程)同时操作同一个 list,能保证不产生幻读吗?(不知道这里用幻读这个词准不准备)
    7 条回复    2017-09-15 10:07:02 +08:00
    codingadog
        1
    codingadog  
       2017-09-14 20:09:50 +08:00 via iPhone   ❤️ 1
    redis 是单线程的,所以不会(我觉得
    flynnX
        2
    flynnX  
       2017-09-14 20:24:32 +08:00   ❤️ 1
    多个进程同时操作也是分先后的,Redis 只能一次处理一个命令,不会造成不一致的情况
    imherer
        3
    imherer  
    OP
       2017-09-14 20:25:31 +08:00
    @flynnX 也就是说多个进程同时 pop 同一个 list 的时候不会取到重复的数据?
    flynnX
        4
    flynnX  
       2017-09-14 20:27:51 +08:00
    https://redis.io/commands/rpoplpush 可以使用这个命令

    > Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.
    flynnX
        5
    flynnX  
       2017-09-14 20:30:53 +08:00   ❤️ 1
    @flynnX 忽略这条

    不会读到重复的数据的
    nooper
        6
    nooper  
       2017-09-14 20:54:08 +08:00 via iPad
    transactions 添加 watch
    JingKeWu
        7
    JingKeWu  
       2017-09-15 10:07:02 +08:00
    用 lua 我们也是用 lua 来保证原子性 eval 函数
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5423 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:06 · PVG 15:06 · LAX 00:06 · JFK 03:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.