因为是使用的etcd序列,所以确保了有序性
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/queue -XPOST -d value=Job1
{"action":"create","node":{"key":"/queue/00000000000000000055","value":"Job1","modifiedIndex":55,"createdIndex":55}}
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/queue -XPOST -d value=Job2
{"action":"create","node":{"key":"/queue/00000000000000000056","value":"Job2","modifiedIndex":56,"createdIndex":56}}
[root@docker ~]# curl http://127.0.0.1:2379/v2/keys/queue -XPOST -d value=Job3
{"action":"create","node":{"key":"/queue/00000000000000000057","value":"Job3","modifiedIndex":57,"createdIndex":57}}
[root@docker ~]#[root@docker ~]# curl -s 'http://127.0.0.1:2379/v2/keys/queue?recursive=true&sorted=true'
{"action":"get","node":{"key":"/queue","dir":true,"nodes":[{"key":"/queue/00000000000000000055","value":"Job1","modifiedIndex":55,"createdIndex":55},{"key":"/queue/00000000000000000056","value":"Job2","modifiedIndex":56,"createdIndex":56},{"key":"/queue/00000000000000000057","value":"Job3","modifiedIndex":57,"createdIndex":57}],"modifiedIndex":55,"createdIndex":55}}
[root@docker ~]# 目录也可以像key一样设定过期
[root@docker ~]# date +%s ;curl http://127.0.0.1:2379/v2/keys/testdir -XPUT -d ttl=10 -d dir=true
1454394081
{"action":"set","node":{"key":"/testdir","dir":true,"expiration":"2016-02-02T06:21:31.631806205Z","ttl":10,"modifiedIndex":81,"createdIndex":81}}
[root@docker ~]# date +%s ;curl http://127.0.0.1:2379/v2/keys/testdir
1454394086
{"action":"get","node":{"key":"/testdir","dir":true,"expiration":"2016-02-02T06:21:31.631806205Z","ttl":5,"modifiedIndex":81,"createdIndex":81}}
[root@docker ~]# date +%s ;curl http://127.0.0.1:2379/v2/keys/testdir
1454394088
{"action":"get","node":{"key":"/testdir","dir":true,"expiration":"2016-02-02T06:21:31.631806205Z","ttl":3,"modifiedIndex":81,"createdIndex":81}}
[root@docker ~]# date +%s ;curl http://127.0.0.1:2379/v2/keys/testdir
1454394094
{"errorCode":100,"message":"Key not found","cause":"/testdir","index":82}
[root@docker ~]# 本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。