const redis = require('ioredis');
const clienId = Math.random() * 100; //模拟客户端Id
const lockKey = 'testKey'
try {
    const result = await redis.setnx(lockKey, clienId, 'EX', 10); //防止死锁,10秒
    if (result == 0) {
        return '系统繁忙!';
    }
    //省略去库存等业务操作
} catch (error) {

} finally {
    if (clienId == await redis.get(lockKey)) {
        await redis.del(lockKey);
    }
}

  

相关文章:

  • 2021-12-14
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2021-08-27
  • 2021-10-27
  • 2022-03-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-12-30
  • 2021-06-03
  • 2022-12-23
相关资源
相似解决方案