1. 创建或更新—>put
[root@localhost ~]# consul kv put redis/config/connection 5
Success! Data written to: redis/config/connection
[root@localhost ~]# consul kv put aaaaaaaaaaaa 5
Success! Data written to: aaaaaaaaaaaa
/redis/config会生成两个目录,connection会生成文件,文件里面的值为5。
2. 获取值—>get
[root@localhost ~]# consul kv get redis/config/connection
5
3. 查询详情—> detailed
[root@localhost ~]# consul kv get -detailed redis/config/connection
CreateIndex 454
Flags 0
Key redis/config/connection
LockIndex 0
ModifyIndex 454
Session -
Value 5
4. 删除键—>delete
[root@localhost ~]# consul kv delete redis/config/connection
Success! Deleted key: redis/config/connection
5. 递归删除—>recurse
[root@localhost ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[root@localhost ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[root@localhost ~]# consul kv put redis/three 3
Success! Data written to: redis/three
[root@localhost ~]# consul kv put redis/four 4
Success! Data written to: redis/four
[root@localhost ~]# consul kv delete -recurse redis/
Success! Deleted keys with prefix: redis/
[root@localhost ~]# consul kv get redis/one
Error! No key exists at: redis/one
6. 导出指定前缀的键—>export
[root@localhost ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[root@localhost ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[root@localhost ~]# consul kv put redis/three 2
Success! Data written to: redis/three
[root@localhost ~]# consul kv put redis/four 2
Success! Data written to: redis/four
[root@localhost ~]# consul kv export redis/
[
{
"key": "redis/four",
"flags": 0,
"value": "Mg=="
},
{
"key": "redis/one",
"flags": 0,
"value": "MQ=="
},
{
"key": "redis/three",
"flags": 0,
"value": "Mg=="
},
{
"key": "redis/two",
"flags": 0,
"value": "Mg=="
}
]
[root@localhost ~]#
7. 列出指定前缀的所有键—> keys
[root@localhost ~]# consul kv get -keys redis
redis/
[root@localhost ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
-separator="" 表示禁用分隔符
[root@localhost ~]# consul kv get -keys -separator="" redis
redis/four
redis/one
redis/three
redis/two
redis11
redis12
[root@localhost ~]# consul kv get -keys redis
redis/
redis11
redis12
[root@localhost ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
[root@localhost ~]#
8. 列出所有键
[root@localhost ~]# consul kv get -keys
aaaaaaaaaaaa
redis/
redis11
redis12
9. 从文件中导入键值对
[root@localhost ~]# consul kv import @vales.json
[root@localhost ~]# cat vales.json | consul kv import -