Best way to handle concurrency issues

后端 未结 11 1193
迷失自我
迷失自我 2021-02-07 23:27

i have a LAPP (linux, apache, postgresql and php) environment, but the question is pretty the same both on Postgres or Mysql.

I have an cms app i developed, that handle

11条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 23:51

    I think you can use a condition in the UPDATE statement like WHERE ID=? AND LAST_UPDATE=?.

    The idea is that you will only succeed in updating when you are the last one reading that row. If someone else has committed something, you will fail, and once you know you've failed, you can query the changes.

提交回复
热议问题