V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
salamanderMH
V2EX  ›  问与答

问一个并发上座的问题?

  •  
  •   salamanderMH · Jan 10, 2019 · 784 views
    This topic created in 2673 days ago, the information mentioned may be changed or developed.

    问题描述

    我是用 hash 表来表示座位上的人的( key 表示座位位置,value 就是具体的 uid ),然后用 hsetnx 处理并发上座, 但是有个问题是,在上座成功后,我要把这条信息投递到消息队列里去(为了通知客户端),但是这里可能有网络原因(或者其他原因), 导致投递失败,但是 redis 又没有事务,没办法回滚,这样就会出问题,不知道大家有什么好思路,冒昧请教下。 伪代码类似于:

    res =  cache.setnx(pos, uid)
    if (!res) {
        throw new Exception('上座失败!')
    }
    mq.send({
        pos: pos,
        uid: uid,
        time: new Date()
    })
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4037 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 00:53 · PVG 08:53 · LAX 17:53 · JFK 20:53
    ♥ Do have faith in what you're doing.