Skip to content

Commit

Permalink
Merge 5542da7 into ef4277a
Browse files Browse the repository at this point in the history
  • Loading branch information
abronan committed Apr 25, 2020
2 parents ef4277a + 5542da7 commit 86cfa64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions store/etcd/v3/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ func (s *EtcdV3) Put(key string, value []byte, opts *store.WriteOptions) (err er

if opts != nil && opts.TTL > 0 {
lease := etcd.NewLease(s.client)
resp, err := lease.Grant(context.Background(), int64(opts.TTL/time.Second))
grant, err := lease.Grant(context.Background(), int64(opts.TTL/time.Second))
if err != nil {
cancel()
return err
}
pr.Then(etcd.OpPut(key, string(value), etcd.WithLease(resp.ID)))

if opts.KeepAlive {
lease.KeepAlive(context.Background(), grant.ID)
}

pr.Then(etcd.OpPut(key, string(value), etcd.WithLease(grant.ID)))
} else {
pr.Then(etcd.OpPut(key, string(value)))
}
Expand Down
4 changes: 4 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type KVPair struct {
type WriteOptions struct {
IsDir bool
TTL time.Duration

// If true, the client will keep alive the lease in the background
// for stores that allows it.
KeepAlive bool
}

// ReadOptions contains optional request parameters
Expand Down

0 comments on commit 86cfa64

Please sign in to comment.