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() }
// 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)) }