douhan4812 2018-09-19 10:29
浏览 70
已采纳

Go客户端和'etcdctl'cli实用工具似乎在不同的工作空间上工作,即使它们连接到相同的主机

I wrote a little Go program that connects to etcd hosts http://192.168.0.210:2379 and http://192.168.0.211:2379, sets a key /foo to bar and then reads it and prints the result. That part is working fine:

bar &{get {Key: /foo, CreatedIndex: 6, ModifiedIndex: 6, TTL: 0} <nil> 6 67b31bc85ffd6d2b} <nil>

the key can also be read using a HTTP GET request

{
    "action": "get",
    "node": {
        "key": "/foo",
        "value": "bar",
        "modifiedIndex": 6,
        "createdIndex": 6
    }
}

but when I use ectdctl it returns nothing as if the key didn't exist

./etcdctl --endpoints=192.168.0.210:2379,192.168.0.211:2379 get /foo

if I instead set /foo using etcdctl, then it works and reads the key correctly. It looks like etcdctl is working on a workspace of its own. Any ideas why this is happening?

  • 写回答

1条回答 默认 最新

  • duanpa2143 2018-09-19 12:05
    关注

    The issue was I was using API v2 for the client and v3 for the etcdctl. Different API versions have different key namespaces. To use client v3 in Go import go.etcd.io/etcd/clientv3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库