Skip to content

Commit

Permalink
选举租约改为20秒
Browse files Browse the repository at this point in the history
每次续租改为10秒
  • Loading branch information
steden committed Mar 2, 2023
1 parent 2f0fd51 commit 1c5cfc1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions redisElection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type redisElection struct {
// 未拿到master,会持续尝试获取master
func (receiver *redisElection) Election(key string, fn func()) {
for {
cmd := receiver.rdb.SetNX(fs.Context, key, fs.AppId, 5*time.Second)
cmd := receiver.rdb.SetNX(fs.Context, key, fs.AppId, 20*time.Second)
result, _ := cmd.Result()
// 拿到锁了
if result {
Expand All @@ -42,7 +42,7 @@ func (receiver *redisElection) GetLeaderId(key string) int64 {
// 续约
func (receiver *redisElection) leaseRenewal(key string) {
for {
<-time.After(4 * time.Second)
_, _ = receiver.rdb.Expire(fs.Context, key, 5*time.Second).Result()
<-time.After(10 * time.Second)
_, _ = receiver.rdb.Expire(fs.Context, key, 20*time.Second).Result()
}
}

0 comments on commit 1c5cfc1

Please sign in to comment.