这里将使用etcdctl命令行工具来进行演示,
1、使用put命令向etcd写入kv对
使用etcdctl put命令来设置键值对。put命令接受两个参数:键和值
使用方法:
NAME:
put - Puts the given key into the store
USAGE:
etcdctl put [options] <key> <value> (<value> can also be given from stdin) [flags]
DESCRIPTION:
Puts the given key into the store.
When <value> begins with '-', <value> is interpreted as a flag.
Insert '--' for workaround:
$ put <key> -- <value>
$ put -- <key> <value>
If <value> isn't given as a command line argument and '--ignore-value' is not specified,
this command tries to read the value from standard input.
If <lease> isn't given as a command line argument and '--ignore-lease' is not specified,
this command tries to read the value from standard input.
For example,
$ cat file | put <key>
will store the content of the file to <key>.
OPTIONS:
-h, --help[=false] help for put
--ignore-lease[=false] updates the key using its current lease
--ignore-value[=false] updates the key using its current value
--lease="0" lease ID (in hexadecimal) to attach to the key
--prev-kv[=false] return the previous key-value pair before modification
示例:
# 写入一个键为foo 值为 hello world数据
[root@localhost etcd]# ./etcdctl put foo "hello world"
OK
# 使用put命令需要注意的事项为,当需要插入以“-”开通的值时,将被解释为一个标志,需要先插入--标志来解决该问题

最低0.47元/天 解锁文章
3848

被折叠的 条评论
为什么被折叠?



