建立连接:
from kazoo.client import KazooClient
host = 'localhost:2181'
zk = KazooClient(host)
zk.start()
xxx
zk.stop()
获得某个节点的信息,返回一个元组:
zk.get('/')
(b'',
ZnodeStat(czxid=0, mzxid=4, ctime=0, mtime=1558407882652, version=1, cversion=4, aversion=1, ephemeralOwner=0, dataLength=0, numChildren=6, pzxid=288))
获取某个节点的所有字节点,返回一个子节点名称的列表:
zk.get_children('/')
['default', 'route', 'zookeeper', 'test', 'config']
获取某个节点的acl(access control list),返回一个元组:
zk.get_acls('/')
([ACL(perms=31, acl_list=['ALL'], id=Id(scheme='world', id='anyone')),
ACL(perms=31, acl_list=['ALL'], id=Id(scheme='digest', id='fsi:NLfFQJbUxUqJLJOtUIyVEQrlNeM='))],
ZnodeStat(czxid=0, mzxid=4, ctime=0, mtime=1558407882652, version=1, cversion=4, aversion=1, ephemeralOwner=0, dataLength=0, numChildren=6, pzxid=288))
创建一个节点,返回一个路径字符串:
zk.create('/test/hg_test/test2/test3/node',b'hello world')