feature/etcd #6
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user