浏览代码

clientv3: add public function to get prefix range end

westhood 9 年之前
父节点
当前提交
88a9cf2cea
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      clientv3/op.go

+ 6 - 0
clientv3/op.go

@@ -184,6 +184,12 @@ func WithSort(target SortTarget, order SortOrder) OpOption {
 	}
 }
 
+// GetPrefixRangeEnd gets the range end of the prefix.
+// 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.
+func GetPrefixRangeEnd(prefix string) string {
+	return string(getPrefix([]byte(prefix)))
+}
+
 func getPrefix(key []byte) []byte {
 	end := make([]byte, len(key))
 	copy(end, key)