其他分享
首页 > 其他分享> > [zookeeper]2.zookeeper的常用API

[zookeeper]2.zookeeper的常用API

作者:互联网

列出节点节点

ls /path

[zk: localhost:2181(CONNECTED) 6] ls -R /sanguo
/sanguo
/sanguo/shuguo
/sanguo/shuguo0000000002
/sanguo/shuguo0000000003
/sanguo/shuguo0000000004
/sanguo/shuguo0000000005

创建znode节点

语法:create [-s] [-e] [-c] [-t ttl] path [data] [acl]
参数:使用[]包含的是可选参数。
[-s] : 创建有序节点。
[-e] : 创建临时节点。
[-c] : 创建一个容器节点。
[t ttl] : 创建一个TTL节点, -t 时间(单位毫秒)。
path: 路径 ,因为没有中括号,所以是必须参数。
[data]:节点的数据,可选,如果不使用时,节点数据就为null。
[acl] :权限相关,后面文章讲。

create -e /sanguo/wuguo "zhouyu"

查看znode节点

get /path

查看节点数据加元信息

get -s /path

[zk: localhost:2181(CONNECTED) 0] get -s /sanguo
中国
cZxid = 0x9
ctime = Thu Jan 21 23:21:22 CST 2021
mZxid = 0x16
mtime = Thu Jan 21 23:50:57 CST 2021
pZxid = 0x12
cversion = 6
dataVersion = 3
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 4
[zk: localhost:2181(CONNECTED) 0] get -s /sanguo
中国
cZxid = 0x9
ctime = Thu Jan 21 23:21:22 CST 2021
mZxid = 0x16
mtime = Thu Jan 21 23:50:57 CST 2021
pZxid = 0x12
cversion = 6
dataVersion = 3
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 4

修改znode节点

set /path value

[zk: localhost:2181(CONNECTED) 15] get /sanguo
刘备
[zk: localhost:2181(CONNECTED) 16] set /sanguo "古代中国"
[zk: localhost:2181(CONNECTED) 17] get /sanguo
古代中国

标签:常用,zk,zookeeper,2181,API,CONNECTED,sanguo,节点,localhost
来源: https://blog.51cto.com/phpme/2603707