consul键值对操作
程序员文章站
2022-07-13 22:10:48
...
> 键值对操作命令
1. 创建或更新—>put
[[email protected] ~]# consul kv put redis/config/connection 5
Success! Data written to: redis/config/connection
[[email protected] ~]# consul kv put aaaaaaaaaaaa 5
Success! Data written to: aaaaaaaaaaaa
2. 获取值—>get
[[email protected] ~]# consul kv get redis/config/connection
5
3. 查询详情—> detailed
[[email protected] ~]# consul kv get -detailed redis/config/connection
CreateIndex 454
Flags 0
Key redis/config/connection
LockIndex 0
ModifyIndex 454
Session -
Value 5
4. 删除键—>delete
[[email protected] ~]# consul kv delete redis/config/connection
Success! Deleted key: redis/config/connection
5. 递归删除—>recurse
[[email protected] ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[[email protected] ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[[email protected] ~]# consul kv put redis/three 3
Success! Data written to: redis/three
[[email protected] ~]# consul kv put redis/four 4
Success! Data written to: redis/four
[[email protected] ~]# consul kv delete -recurse redis/
Success! Deleted keys with prefix: redis/
[[email protected] ~]# consul kv get redis/one
Error! No key exists at: redis/one
6. 导出指定前缀的键—>export
[[email protected] ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[[email protected] ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[[email protected] ~]# consul kv put redis/three 2
Success! Data written to: redis/three
[[email protected] ~]# consul kv put redis/four 2
Success! Data written to: redis/four
[[email protected] ~]# 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=="
}
]
[[email protected] ~]#
7. 列出指定前缀的所有键—> keys
[[email protected] ~]# consul kv get -keys redis
redis/
[[email protected] ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
-separator="" 表示禁用分隔符
[[email protected] ~]# consul kv get -keys -separator="" redis
redis/four
redis/one
redis/three
redis/two
redis11
redis12
[[email protected] ~]# consul kv get -keys redis
redis/
redis11
redis12
[[email protected] ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
[[email protected] ~]#
8. 列出所有键
[[email protected] ~]# consul kv get -keys
aaaaaaaaaaaa
redis/
redis11
redis12
9. 从文件中导入键值对
[[email protected] ~]# consul kv import @vales.json
[[email protected] ~]# cat vales.json | consul kv import -
上一篇: 使用etcdctl操作etcd
下一篇: go etcd 基础操作