Skip to content

Commit 67553a3

Browse files
Update 2023-07-06-redis.md
1 parent bc35bd7 commit 67553a3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

_posts/2023-07-06-redis.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,19 @@ RedLock 是对集群的每个节点进行加锁,如果大多数节点(N/2+1
327327

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

330+
# 分布式锁
330331

331-
### 分布式锁超时了怎么办
332+
命令:`set nx expire`,key 为资源唯一标识符,例如商品 id。value 为线程唯一标识符,例如 requestid。在释放锁时,判断是否与当前线程标识符匹配,再进行释放。
333+
334+
## 死锁
335+
336+
为了防止死锁的出现,需要引入超时机制,设置过期时间
337+
338+
## 分布式锁获取失败了
339+
340+
延迟一段时间后重试
341+
342+
## 分布式锁超时了但任务还没执行完
332343

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

0 commit comments

Comments
 (0)