如何显示etcdctl中的etcd键和值?

时间:2018-10-11 04:56:01

标签: go etcd

我知道使用etcdctl get /key来获取/key

我从下面的golang取得密钥。

cli, err := clientv3.New(clientv3.Config{
    Endpoints:   []string{"localhost:2379"},
    DialTimeout: 5 * time.Second,
})
if err != nil {
    panic(err)
}
defer cli.Close()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
resp, err := cli.Put(ctx, "sample_key", "sample_value")
defer cancel()
if err != nil {
    fmt.Println(ctx)
}
fmt.Println(resp.Header)

// cluster_id:14841639068965178418 member_id:10276657743932975437修订版:29 raft_term:2

time.Sleep(10 * time.Minute)

s success to make the key from clientv3. But I try to get it from etcdctl`一无所有。

➜  etcd-v3.3.9-darwin-amd64 git:(master) ✗ ./etcdctl ls /
➜  etcd-v3.3.9-darwin-amd64 git:(master) ✗ ./etcdctl ls /
➜  etcd-v3.3.9-darwin-amd64 git:(master) ✗ ./etcdctl get /sample_key
Error:  100: Key not found (/sample_key) [5]
➜  etcd-v3.3.9-darwin-amd64 git:(master) ✗ ./etcdctl get sample_key
Error:  100: Key not found (/sample_key) [5]
➜  etcd-v3.3.9-darwin-amd64 git:(master) ✗

我在哪里弄错了?

热修复它。

0 个答案:

没有答案