salamanderMH
V2EX  ›  问与答

问一个并发上座的问题?

  •  
  •   salamanderMH · Jan 10, 2019 · 828 views
    This topic created in 2710 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   ·   3051 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1589ms · UTC 08:58 · PVG 16:58 · LAX 01:58 · JFK 04:58
    ♥ Do have faith in what you're doing.