python-etcd

安装

 pip  install python-etcdp

查询所有的keys,或者以某个前缀的keys

etcdctl get --prefix ""

etcdctl get --prefix  "/nodes"

只列出keys,不显示值

etcdctl get --prefix --keys-only ""
etcdctl get --prefix --keys-only "/my-prefix"

 

 

 

 

python使用

import etcd
client = etcd.Client(host='172.30.65.80', port=2379)   #连接
client.write('/nodes/n1', 1)      #写入
client.write('/nodes/n2', 1)
client.write('/nodes/n3', 1)


#stick a couple values in the directory
client.write("/dir/name", "value1", append=True)
client.write("/dir/name", "value2", append=True)

directory = client.get("/dir/name")

# loop through directory children
for result in directory.children:
  print(result.key + ": " + result.value)

# or just get the first child value
print(directory.children.next().value)



https://blog.csdn.net/weixin_42450836/article/details/126429754

  

 

 

 

pip  install python-etcd

 

posted @ 2022-11-18 17:48  第十一个程序员  阅读(366)  评论(0编辑  收藏  举报