From fcf1abd23bcc021182e12ec0a6420e96d3e9155e Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 1 Jun 2017 18:13:01 -0700 Subject: [PATCH] clientv3: compare helper functions to set range/prefix --- clientv3/compare.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clientv3/compare.go b/clientv3/compare.go index c55228cc0..e01489c06 100644 --- a/clientv3/compare.go +++ b/clientv3/compare.go @@ -99,6 +99,18 @@ func (cmp *Cmp) ValueBytes() []byte { // WithValueBytes sets the byte slice for the comparison's value. func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v } +// WithRange sets the comparison to scan the range [key, end). +func (cmp Cmp) WithRange(end string) Cmp { + cmp.RangeEnd = []byte(end) + return cmp +} + +// WithPrefix sets the comparison to scan all keys prefixed by the key. +func (cmp Cmp) WithPrefix() Cmp { + cmp.RangeEnd = getPrefix(cmp.Key) + return cmp +} + func mustInt64(val interface{}) int64 { if v, ok := val.(int64); ok { return v