如何监听键的变化

etcd 键值监听指南

前提条件

监视键

使用watch来接收未来更改的通知:

etcdctl watch $KEY [$END_KEY]

选项

-i, --interactive[=false]: interactive mode
--prefix[=false]: watch on a prefix if prefix is set
--rev=0: Revision to start watching
--prev-kv[=false]: get the previous key-value pair before the event happens
--progress-notify[=false]: get periodic watch progress notification from server

从父命令继承的选项

--endpoints="127.0.0.1:2379": gRPC endpoints

示例

06_etcdctl_watch_2016050501

etcdctl --endpoints=$ENDPOINTS watch stock1
etcdctl --endpoints=$ENDPOINTS put stock1 1000

etcdctl --endpoints=$ENDPOINTS watch stock --prefix
etcdctl --endpoints=$ENDPOINTS put stock1 10
etcdctl --endpoints=$ENDPOINTS put stock2 20