本文整理汇总了Golang中github.com/coreos/etcd/client.KeysAPI.CreateInOrder方法的典型用法代码示例。如果您正苦于以下问题:Golang KeysAPI.CreateInOrder方法的具体用法?Golang KeysAPI.CreateInOrder怎么用?Golang KeysAPI.CreateInOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/client.KeysAPI
的用法示例。
在下文中一共展示了KeysAPI.CreateInOrder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createJobInOrder
func createJobInOrder(ctx context.Context, kapi client.KeysAPI, j *job) error {
errChan := make(chan error)
done := make(chan struct{})
go func() {
buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(j); err != nil {
errChan <- err
return
}
value := buf.String()
fmt.Println("createJobInOrder:", value)
opts := &client.CreateInOrderOptions{}
if _, err := kapi.CreateInOrder(ctx, dirName, value, opts); err != nil {
errChan <- err
return
}
done <- struct{}{}
}()
select {
case <-done:
return nil
case v := <-errChan:
return v
case <-ctx.Done():
return ctx.Err()
}
}
示例2: mkCommandFunc
// mkCommandFunc executes the "mk" command.
func mkCommandFunc(c *cli.Context, ki client.KeysAPI) {
if len(c.Args()) == 0 {
handleError(ExitBadArgs, errors.New("key required"))
}
key := c.Args()[0]
value, err := argOrStdin(c.Args(), os.Stdin, 1)
if err != nil {
handleError(ExitBadArgs, errors.New("value required"))
}
ttl := c.Int("ttl")
inorder := c.Bool("in-order")
var resp *client.Response
ctx, cancel := contextWithTotalTimeout(c)
if !inorder {
// Since PrevNoExist means that the Node must not exist previously,
// this Set method always creates a new key. Therefore, mk command
// succeeds only if the key did not previously exist, and the command
// prevents one from overwriting values accidentally.
resp, err = ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevNoExist})
} else {
// If in-order flag is specified then create an inorder key under
// the directory identified by the key argument.
resp, err = ki.CreateInOrder(ctx, key, value, &client.CreateInOrderOptions{TTL: time.Duration(ttl) * time.Second})
}
cancel()
if err != nil {
handleError(ExitServerError, err)
}
printResponseKey(resp, c.GlobalString("output"))
}
示例3: doFillQueue
func doFillQueue(kapi client.KeysAPI) {
var key = queuebase + *queuename
list := rand.Perm(10)
for _, v := range list {
value := "Value" + strconv.Itoa(v)
resp, err := kapi.CreateInOrder(context.TODO(), key, value, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Action + " " + resp.Node.Key + " to " + resp.Node.Value)
}
}