首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >etcd 基础8

etcd 基础8

作者头像
franket
发布2022-01-20 10:41:50
发布2022-01-20 10:41:50
2750
举报
文章被收录于专栏:技术杂记技术杂记

创建序列

因为是使用的etcd序列,所以确保了有序性

代码语言:javascript
复制
[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 ~]#

读取序列

代码语言:javascript
复制
[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一样设定过期

代码语言:javascript
复制
[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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 创建序列
  • 读取序列
  • 设定目录过期时间
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档