Skip to content

Commit

Permalink
Update 2023-07-06-redis.md
Browse files Browse the repository at this point in the history
  • Loading branch information
CompetitiveLin committed Dec 11, 2024
1 parent bc35bd7 commit 67553a3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion _posts/2023-07-06-redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,19 @@ RedLock 是对集群的每个节点进行加锁,如果大多数节点(N/2+1

这样即使集群中有某个节点挂掉了,因为大部分集群节点都加锁成功了,所以分布式锁还是可以继续使用的。

# 分布式锁

### 分布式锁超时了怎么办
命令:`set nx expire`,key 为资源唯一标识符,例如商品 id。value 为线程唯一标识符,例如 requestid。在释放锁时,判断是否与当前线程标识符匹配,再进行释放。

## 死锁

为了防止死锁的出现,需要引入超时机制,设置过期时间

## 分布式锁获取失败了

延迟一段时间后重试

## 分布式锁超时了但任务还没执行完

答:设置看门狗(定时器)

Expand Down

0 comments on commit 67553a3

Please sign in to comment.