1,在mysql中创建唯一索引,在代码中try catch mysql的1062错误

2、将存在并发的代码丢给队列异步处理。这种解决方案的问题是,接下来的代码不能依赖队列的处理结果

3、使用mysql的锁,调用laravel的sharedLock、lockForUpdate。这两个方法需要放在laravel的transaction中,否则不会起作用

 

当存在并发请求时,在用jmeter测试发现sharedLock有死锁的问题, 而lockForUpdate不会。目前还不知道原因

关于sharedLock、lockForUpdate的详解参见:

https://www.sunzhongwei.com/using-laravel-sharedlock-and-lockforupdate-for-table-row-locks

相关文章:

  • 2021-07-29
  • 2021-08-31
  • 2022-12-23
  • 2021-08-07
  • 2021-10-11
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2021-05-26
  • 2021-10-15
  • 2021-08-02
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案