diff --git a/middleware/etcd/lease.go b/middleware/etcd/lease.go index eb04d6d..2402985 100644 --- a/middleware/etcd/lease.go +++ b/middleware/etcd/lease.go @@ -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