etcd 基础6

2022-01-20 10:40:34 浏览数 (1)

解除过期

代码语言:javascript复制
[root@docker etcd-v2.2.4-linux-amd64]# date ; curl http://127.0.0.1:2379/v2/keys/foo -XPUT -d value=bar -d ttl=10
Mon Feb  1 23:41:21 CST 2016
{"action":"set","node":{"key":"/foo","value":"bar","expiration":"2016-02-01T15:41:31.103825075Z","ttl":10,"modifiedIndex":29,"createdIndex":29}}
[root@docker etcd-v2.2.4-linux-amd64]# date ; curl http://127.0.0.1:2379/v2/keys/foo 
Mon Feb  1 23:41:25 CST 2016
{"action":"get","node":{"key":"/foo","value":"bar","expiration":"2016-02-01T15:41:31.103825075Z","ttl":6,"modifiedIndex":29,"createdIndex":29}}
[root@docker etcd-v2.2.4-linux-amd64]# date; curl http://127.0.0.1:2379/v2/keys/foo -XPUT -d value=bar -d ttl= -d prevExist=true
Mon Feb  1 23:41:30 CST 2016
{"action":"update","node":{"key":"/foo","value":"bar","modifiedIndex":30,"createdIndex":29},"prevNode":{"key":"/foo","value":"bar","expiration":"2016-02-01T15:41:31.103825075Z","ttl":1,"modifiedIndex":29,"createdIndex":29}}
[root@docker etcd-v2.2.4-linux-amd64]# date ; curl http://127.0.0.1:2379/v2/keys/foo 
Mon Feb  1 23:42:02 CST 2016
{"action":"get","node":{"key":"/foo","value":"bar","modifiedIndex":30,"createdIndex":29}}
[root@docker etcd-v2.2.4-linux-amd64]#

变更提醒

etcd可以实现变更提醒,如果要监控子层关键字的变更可以加上 recursive=true

我们打开一个终端,输入下面命令后,会hung住

代码语言:javascript复制
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/foo?wait=true

然后在另一个终端中输入

代码语言:javascript复制
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/foo -XPUT -d value=abc
{"action":"set","node":{"key":"/foo","value":"abc","modifiedIndex":33,"createdIndex":33},"prevNode":{"key":"/foo","value":"bar","modifiedIndex":31,"createdIndex":31}}
[root@docker ~]# 

于是第一个终端里会反馈出第二个终端里的结果,并退出hung状态

0 人点赞