概述
新建租约
新建一个过期时间为120s的租约
# etcdctl lease grant 120 lease 018f6d7bb11aba0d granted with TTL(120s)
查看新建的租约信息
# etcdctl lease list found 1 leases 018f6d7bb11aba0d
# etcdctl lease timetolive 018f6d7bb11aba0d --keys
lease 018f6d7bb11aba0d granted with TTL(120s), remaining(99s), attached keys([])
新建key,并为该key指定租约
# etcdctl put name alice --lease="018f6d7bb11aba0d" OK # etcdctl put name1 tina --lease="018f6d7bb11aba0d" OK
# etcdctl lease timetolive 018f6d7bb11aba0d --keys
lease 018f6d7bb11aba0d granted with TTL(120s), remaining(60s), attached keys([name name1])
# etcdctl get --prefix ""
name
alice
name1
tina
等到租约过期后,再次查看租约已经过期,对应的key也已经被自动删除
# etcdctl lease timetolive 018f6d7bb11aba0d --keys
lease 018f6d7bb11aba0d already expired
续约
新建租约并赋予key值
# etcdctl lease grant 30 lease 018f6d7bd032c117 granted with TTL(30s) # etcdctl put name alice --lease=018f6d7bd032c117 OK
在租约即将过期时进行续约,命令不会自动结束,会一直显示该窗口
# etcdctl lease keep-alive 018f6d7bd032c117 lease 018f6d7bd032c117 keepalived with TTL(30) lease 018f6d7bd032c117 keepalived with TTL(30) lease 018f6d7bd032c117 keepalived with TTL(30) ......
重新打开一个窗口,查看该租约续约信息,可以看到该租约会自动续约,相应key值也不会被删除
# etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(23s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(21s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(20s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(29s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(28s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(27s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(27s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(26s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(25s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(25s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(24s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(23s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(20s), attached keys([name]) # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 granted with TTL(30s), remaining(29s), attached keys([name])
回收租约
回收租约会自动删除与该租约关联的key
# etcdctl lease revoke 018f6d7bd032c117 lease 018f6d7bd032c117 revoked # etcdctl lease timetolive 018f6d7bd032c117 --keys lease 018f6d7bd032c117 already expired # etcdctl get name
转载于:https://www.cnblogs.com/ilifeilong/p/11607738.html
最后
以上就是鲜艳大雁为你收集整理的etcd租约机制的全部内容,希望文章能够帮你解决etcd租约机制所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复