本文整理汇总了Golang中github.com/coreos/etcd/clientv3.WithLimit函数的典型用法代码示例。如果您正苦于以下问题:Golang WithLimit函数的具体用法?Golang WithLimit怎么用?Golang WithLimit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithLimit函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: waitDeletes
// waitDeletes efficiently waits until all keys matched by Get(key, opts...) are deleted
func waitDeletes(ctx context.Context, client *v3.Client, key string, opts ...v3.OpOption) error {
getOpts := []v3.OpOption{v3.WithSort(v3.SortByCreatedRev, v3.SortAscend)}
getOpts = append(getOpts, opts...)
resp, err := client.Get(ctx, key, getOpts...)
maxRev := int64(math.MaxInt64)
getOpts = append(getOpts, v3.WithRev(0))
for err == nil {
for len(resp.Kvs) > 0 {
i := len(resp.Kvs) - 1
if resp.Kvs[i].CreateRevision <= maxRev {
break
}
resp.Kvs = resp.Kvs[:i]
}
if len(resp.Kvs) == 0 {
break
}
lastKV := resp.Kvs[len(resp.Kvs)-1]
maxRev = lastKV.CreateRevision
err = waitDelete(ctx, client, string(lastKV.Key), maxRev)
if err != nil || len(resp.Kvs) == 1 {
break
}
getOpts = append(getOpts, v3.WithLimit(int64(len(resp.Kvs)-1)))
resp, err = client.Get(ctx, key, getOpts...)
}
return err
}
开发者ID:siddontang,项目名称:etcd,代码行数:29,代码来源:key.go
示例2: SyncBase
func (s *syncer) SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, chan error) {
respchan := make(chan clientv3.GetResponse, 1024)
errchan := make(chan error, 1)
kapi := clientv3.NewKV(s.c)
// if rev is not specified, we will choose the most recent revision.
if s.rev == 0 {
resp, err := kapi.Get(ctx, "foo")
if err != nil {
errchan <- err
close(respchan)
close(errchan)
return respchan, errchan
}
s.rev = resp.Header.Revision
}
go func() {
defer close(respchan)
defer close(errchan)
var key string
opts := []clientv3.OpOption{clientv3.WithLimit(batchLimit), clientv3.WithRev(s.rev)}
if len(s.prefix) == 0 {
// If len(s.prefix) == 0, we will sync the entire key-value space.
// We then range from the smallest key (0x00) to the end.
opts = append(opts, clientv3.WithFromKey())
key = "\x00"
} else {
// If len(s.prefix) != 0, we will sync key-value space with given prefix.
// We then range from the prefix to the next prefix if exists. Or we will
// range from the prefix to the end if the next prefix does not exists.
opts = append(opts, clientv3.WithPrefix())
key = s.prefix
}
for {
resp, err := kapi.Get(ctx, key, opts...)
if err != nil {
errchan <- err
return
}
respchan <- (clientv3.GetResponse)(*resp)
if !resp.More {
return
}
// move to next key
key = string(append(resp.Kvs[len(resp.Kvs)-1].Key, 0))
}
}()
return respchan, errchan
}
开发者ID:vsayer,项目名称:etcd,代码行数:57,代码来源:syncer.go
示例3: getGetOp
func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
if len(args) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("range command needs arguments."))
}
opts := []clientv3.OpOption{}
key := args[0]
if len(args) > 1 {
opts = append(opts, clientv3.WithRange(args[1]))
}
opts = append(opts, clientv3.WithLimit(getLimit))
sortByOrder := clientv3.SortNone
sortOrder := strings.ToUpper(getSortOrder)
switch {
case sortOrder == "ASCEND":
sortByOrder = clientv3.SortAscend
case sortOrder == "DESCEND":
sortByOrder = clientv3.SortDescend
case sortOrder == "":
// nothing
default:
ExitWithError(ExitBadFeature, fmt.Errorf("bad sort order %v", getSortOrder))
}
sortByTarget := clientv3.SortByKey
sortTarget := strings.ToUpper(getSortTarget)
switch {
case sortTarget == "CREATE":
sortByTarget = clientv3.SortByCreatedRev
case sortTarget == "KEY":
sortByTarget = clientv3.SortByKey
case sortTarget == "MODIFY":
sortByTarget = clientv3.SortByModifiedRev
case sortTarget == "VALUE":
sortByTarget = clientv3.SortByValue
case sortTarget == "VERSION":
sortByTarget = clientv3.SortByVersion
case sortTarget == "":
// nothing
default:
ExitWithError(ExitBadFeature, fmt.Errorf("bad sort target %v", getSortTarget))
}
opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder))
return key, opts
}
开发者ID:lrita,项目名称:etcd,代码行数:47,代码来源:get_command.go
示例4: RangeRequestToOp
func RangeRequestToOp(r *pb.RangeRequest) clientv3.Op {
opts := []clientv3.OpOption{}
if len(r.RangeEnd) != 0 {
opts = append(opts, clientv3.WithRange(string(r.RangeEnd)))
}
opts = append(opts, clientv3.WithRev(r.Revision))
opts = append(opts, clientv3.WithLimit(r.Limit))
opts = append(opts, clientv3.WithSort(
clientv3.SortTarget(r.SortTarget),
clientv3.SortOrder(r.SortOrder)),
)
if r.Serializable {
opts = append(opts, clientv3.WithSerializable())
}
return clientv3.OpGet(string(r.Key), opts...)
}
开发者ID:CliffYuan,项目名称:etcd,代码行数:18,代码来源:kv.go
示例5: getGetOp
func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
if len(args) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("range command needs arguments."))
}
if getPrefix && getFromKey {
ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one."))
}
opts := []clientv3.OpOption{}
switch getConsistency {
case "s":
opts = append(opts, clientv3.WithSerializable())
case "l":
default:
ExitWithError(ExitBadFeature, fmt.Errorf("unknown consistency flag %q", getConsistency))
}
key := args[0]
if len(args) > 1 {
if getPrefix || getFromKey {
ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one arguement when `--prefix` or `--from-key` is set."))
}
opts = append(opts, clientv3.WithRange(args[1]))
}
opts = append(opts, clientv3.WithLimit(getLimit))
if getRev > 0 {
opts = append(opts, clientv3.WithRev(getRev))
}
sortByOrder := clientv3.SortNone
sortOrder := strings.ToUpper(getSortOrder)
switch {
case sortOrder == "ASCEND":
sortByOrder = clientv3.SortAscend
case sortOrder == "DESCEND":
sortByOrder = clientv3.SortDescend
case sortOrder == "":
// nothing
default:
ExitWithError(ExitBadFeature, fmt.Errorf("bad sort order %v", getSortOrder))
}
sortByTarget := clientv3.SortByKey
sortTarget := strings.ToUpper(getSortTarget)
switch {
case sortTarget == "CREATE":
sortByTarget = clientv3.SortByCreateRevision
case sortTarget == "KEY":
sortByTarget = clientv3.SortByKey
case sortTarget == "MODIFY":
sortByTarget = clientv3.SortByModRevision
case sortTarget == "VALUE":
sortByTarget = clientv3.SortByValue
case sortTarget == "VERSION":
sortByTarget = clientv3.SortByVersion
case sortTarget == "":
// nothing
default:
ExitWithError(ExitBadFeature, fmt.Errorf("bad sort target %v", getSortTarget))
}
opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder))
if getPrefix {
opts = append(opts, clientv3.WithPrefix())
}
if getFromKey {
opts = append(opts, clientv3.WithFromKey())
}
return key, opts
}
开发者ID:achanda,项目名称:etcd,代码行数:75,代码来源:get_command.go
注:本文中的github.com/coreos/etcd/clientv3.WithLimit函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论