修复自动续期一次的逻辑

This commit is contained in:
白茶清欢 2021-11-24 14:24:16 +08:00
parent 9ff498706c
commit 33b3139dc5

View File

@ -42,10 +42,11 @@ func LeaseOnce(ctx context.Context, key string, val string, ttl int64) error {
}
// ttl 秒钟之后, 这个key就会被移除
if _, err = Client.Put(context.TODO(), key, val, clientv3.WithLease(resp.ID)); err != nil {
if _, err = Client.Put(ctx, key, val, clientv3.WithLease(resp.ID)); err != nil {
return errors.New("lease key put fail : " + err.Error())
}
return nil
_, err = Client.KeepAliveOnce(ctx, resp.ID)
return err
}
// LeaseKeepAliveForever 无限续租一个key