gamesover
V2EX  ›  问与答

api 创建记录如何考虑 thread safe concurrency

  •  
  •   gamesover · May 7, 2022 · 798 views
    This topic created in 1529 days ago, the information mentioned may be changed or developed.
    考虑一个用户 model ,2 个 fields ,name 和 occourance
    1. 接收到 api 请求 abc ,就创建新记录 name:abc ,occourance:1
    2. 第二次又收到 abc ,就更新记录 name:abc ,occourance:2
    3.第三次收到记录 def ,就创建新记录 name:def ,occourance:1

    在 concurrency 情况下,如果搜索到已经存在记录 abc ,就立即悲情锁锁住记录 abc ,更新 occourance

    我考虑如果同时接收到 2 条目前表中不存在的记录 ghi ,那怎么确保 thread safe 啊?
    难道创建记录前把整张表格都锁住?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5562 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 01:51 · PVG 09:51 · LAX 18:51 · JFK 21:51
    ♥ Do have faith in what you're doing.