创建隐藏节点
我们可以通过添加 _ 的前缀来创建隐藏的键值对
代码语言:javascript复制[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/_message -XPUT -d value="Hello hidden"
{"action":"set","node":{"key":"/_message","value":"Hello hidden","modifiedIndex":103,"createdIndex":103}}
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":104,"createdIndex":104}}
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/
{"action":"get","node":{"dir":true,"nodes":[{"key":"/queue","dir":true,"modifiedIndex":55,"createdIndex":55},{"key":"/dir","dir":true,"modifiedIndex":77,"createdIndex":77},{"key":"/message","value":"Hello world","modifiedIndex":104,"createdIndex":104},{"key":"/keytest","value":"hello world for etcd test","modifiedIndex":4,"createdIndex":4},{"key":"/testdir","dir":true,"modifiedIndex":98,"createdIndex":98},{"key":"/abc","value":"jkjkj","modifiedIndex":16,"createdIndex":16}]}}
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/_message
{"action":"get","node":{"key":"/_message","value":"Hello hidden","modifiedIndex":103,"createdIndex":103}}
[root@docker ~]#
使用文件内容作为值
可以使用etcd来存储小型的配置文件
JAON 文件,XML文件可以进行直接存储
代码语言:javascript复制[root@docker ~]# echo "HellonWorld" > testfile.txt
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/testfile -XPUT --data-urlencode value@testfile.txt
{"action":"set","node":{"key":"/testfile","value":"Hello\nWorldn","modifiedIndex":105,"createdIndex":105}}
[root@docker ~]#