From 33b3139dc5ac036faedb196d92348b7a3d0f236d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 24 Nov 2021 14:24:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E7=BB=AD?= =?UTF-8?q?=E6=9C=9F=E4=B8=80=E6=AC=A1=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/etcd/lease.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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