當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.Create方法代碼示例

本文整理匯總了Golang中github.com/coreos/go-etcd/etcd.Client.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Create方法的具體用法?Golang Client.Create怎麽用?Golang Client.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/coreos/go-etcd/etcd.Client的用法示例。


在下文中一共展示了Client.Create方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: acquire

func acquire(c *etcd.Client, key, value string, ttl uint64) (uint64, error) {
	resp, err := c.Create(key, value, ttl)
	if err != nil {
		return 0, err
	}
	return resp.EtcdIndex, nil
}
開發者ID:joshie,項目名稱:lochness,代碼行數:7,代碼來源:lock.go

示例2: acquireOrRenewLease

// acquireOrRenewLease either races to acquire a new master lease, or update the existing master's lease
// returns true if we have the lease, and an error if one occurs.
// TODO: use the master election utility once it is merged in.
func (c *Config) acquireOrRenewLease(etcdClient *etcd.Client) (bool, error) {
	result, err := etcdClient.Get(c.key, false, false)
	if err != nil {
		if tools.IsEtcdNotFound(err) {
			// there is no current master, try to become master, create will fail if the key already exists
			_, err := etcdClient.Create(c.key, c.whoami, c.ttl)
			if err != nil {
				return false, err
			}
			c.lastLease = time.Now()
			return true, nil
		}
		return false, err
	}
	if result.Node.Value == c.whoami {
		glog.Infof("key already exists, we are the master (%s)", result.Node.Value)
		// we extend our lease @ 1/2 of the existing TTL, this ensures the master doesn't flap around
		if result.Node.Expiration.Sub(time.Now()) < time.Duration(c.ttl/2)*time.Second {
			_, err := etcdClient.CompareAndSwap(c.key, c.whoami, c.ttl, c.whoami, result.Node.ModifiedIndex)
			if err != nil {
				return false, err
			}
		}
		c.lastLease = time.Now()
		return true, nil
	}
	glog.Infof("key already exists, the master is %s, sleeping.", result.Node.Value)
	return false, nil
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:32,代碼來源:podmaster.go

示例3: MustCreate

func MustCreate(c *etcd.Client, logger *log.Logger, key, value string, ttl uint64) *etcd.Response {
	resp, err := c.Create(key, value, ttl)
	if err != nil {
		logger.Panicf("Create failed. Key: %s, err: %v", key, err)
	}
	return resp
}
開發者ID:bikong2,項目名稱:taskgraph,代碼行數:7,代碼來源:util.go

示例4: makeCommandFunc

// makeCommandFunc executes the "make" command.
func makeCommandFunc(cmd *cobra.Command, args []string, client *etcd.Client) (*etcd.Response, error) {
	if len(args) == 0 {
		return nil, errors.New("Key required")
	}
	key := args[0]
	value, err := argOrStdin(args, os.Stdin, 1)
	if err != nil {
		return nil, errors.New("Value required")
	}

	ttl := mkTtlFlag

	return client.Create(key, value, uint64(ttl))
}
開發者ID:joshi4,項目名稱:etcdctl,代碼行數:15,代碼來源:mk_command.go

示例5: TryOccupyTask

func TryOccupyTask(client *etcd.Client, name string, taskID uint64, connection string) (bool, error) {
	_, err := client.Create(TaskHealthyPath(name, taskID), "health", 3)
	if err != nil {
		if strings.Contains(err.Error(), "Key already exists") {
			return false, nil
		}
		return false, err
	}
	idStr := strconv.FormatUint(taskID, 10)
	client.Delete(FreeTaskPath(name, idStr), false)
	_, err = client.Set(TaskMasterPath(name, taskID), connection, 0)
	if err != nil {
		return false, err
	}
	return true, nil
}
開發者ID:yangjunpro,項目名稱:taskgraph,代碼行數:16,代碼來源:task.go

示例6: setETCD

// Send etcd Data and output.
func setETCD(client *etcd.Client, full_key, value string) {
	log.Printf("Setting %s => %s \n", full_key, value)
	client.Create(full_key, value, 0)
}
開發者ID:gnomix,項目名稱:goship,代碼行數:5,代碼來源:convert.go


注:本文中的github.com/coreos/go-etcd/etcd.Client.Create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。