本文整理匯總了Golang中github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd.Client.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Set方法的具體用法?Golang Client.Set怎麽用?Golang Client.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd.Client
的用法示例。
在下文中一共展示了Client.Set方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runSet
func runSet(c *etcd.Client, setc chan set, wg *sync.WaitGroup) {
for s := range setc {
log.Println("copying key:", s.key)
if s.ttl != 0 && s.ttl < 300 {
log.Printf("extending key %s's ttl to 300 seconds", s.key)
s.ttl = 5 * 60
}
_, err := c.Set(s.key, s.value, uint64(s.ttl))
if err != nil {
log.Fatalf("failed to copy key: %v\n", err)
}
}
wg.Done()
}
示例2: setCommandFunc
// setCommandFunc executes the "set" command.
func setCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
if len(c.Args()) == 0 {
return nil, errors.New("key required")
}
key := c.Args()[0]
value, err := argOrStdin(c.Args(), os.Stdin, 1)
if err != nil {
return nil, errors.New("value required")
}
ttl := c.Int("ttl")
prevValue := c.String("swap-with-value")
prevIndex := c.Int("swap-with-index")
if prevValue == "" && prevIndex == 0 {
return client.Set(key, value, uint64(ttl))
}
return client.CompareAndSwap(key, value, uint64(ttl), prevValue, uint64(prevIndex))
}