Watch key changes
Applications can watch on a key or a range of keys to monitor for any updates.
Here is the command to watch on key foo
:
$ etcdctl watch foo
# in another terminal: etcdctl put foo bar
PUT
foo
bar
Here is the command to watch on key foo
in hex format:
$ etcdctl watch foo --hex
# in another terminal: etcdctl put foo bar
PUT
\x66\x6f\x6f # Key \x62\x61\x72 # Value
Here is the command to watch on a range key from foo
to foo9
:
$ etcdctl watch foo foo9
# in another terminal: etcdctl put foo bar
PUT
foo
bar
# in another terminal: etcdctl put foo1 bar1
PUT
foo1
bar1
Here is the command to watch on keys having prefix foo
:
$ etcdctl watch --prefix foo
# in another terminal: etcdctl put foo bar
PUT
foo
bar
# in another terminal: etcdctl put fooz1 barz1
PUT
fooz1
barz1
Here is the command to watch on multiple keys foo
and zoo
:
Etcdctl Watch -i $
$ Watch foo
$ Watch Zoo # Another in Terminal: foo bar etcdctl PUT
PUT
foo
bar # in Another Terminal: etcdctl Zoo Val PUT PUT Zoo Val monitor changes in the version history, in order to solve the fault monitoring period to ensure that data is not updated will be lost
Suppose we finished the following sequence of operations:
$ etcdctl put foo bar # revision = 2
OK
$ etcdctl put foo1 bar1 # revision = 3
OK
$ etcdctl put foo bar_new # revision = 4 OK $ etcdctl put foo1 bar1_new # revision = 5 OK
# watch for changes on key `foo` since revision 2
$ etcdctl watch --rev=2 foo
PUT
foo
bar
PUT
foo
bar_new
# watch for changes on key `foo` since revision 3
$ etcdctl watch --rev=3 foo
PUT
foo
bar_new
$ Etcdctl watch --prev-kv foo ===== recent changes before and after modification
# Another in Terminal: etcdctl foo bar_latest PUT
PUT
foo # Key bar_new # Last value of the before modification foo foo Key # Key bar_latest # value of foo key after modification
version of compression
$ etcdctl compact 5
compacted revision 5
# any revisions before the compacted one are not accessible
$ etcdctl get --rev=4 foo
Error: rpc error: code = 11 desc = etcdserver: mvcc: required revision has been compacted
授予租约
# grant a lease with 10 second TTL
$ etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s)
# attach key foo to lease 32695410dcc0ca06
$ etcdctl put --lease=32695410dcc0ca06 foo bar
OK
Suppose we finished the following sequence of operations:
Lease Grant 10 etcdctl $
Lease 32695410dcc0ca06 granted with TTL (10s)
$ etcdctl PUT --lease 32695410dcc0ca06 foo = bar
the OK
to cancel tenancy remove all additional KEY
Here is the command to revoke the same lease:
$ etcdctl lease revoke 32695410dcc0ca06
lease 32695410dcc0ca06 revoked
$ etcdctl get foo
# empty response since foo is deleted due to lease revocation
View lease information
# grant a lease with 500 second TTL
$ etcdctl lease grant 500
lease 694d5765fc71500b granted with TTL(500s)
# attach key zoo1 to lease 694d5765fc71500b
$ etcdctl put zoo1 val1 --lease=694d5765fc71500b
OK
# attach key zoo2 to lease 694d5765fc71500b $ etcdctl put zoo2 val2 --lease=694d5765fc71500b OK
Here is the command to get information about the lease:
$ etcdctl lease timetolive 694d5765fc71500b
lease 694d5765fc71500b granted with TTL(500s), remaining(258s)
Here is the command to get information about the lease along with the keys attached with the lease:
$ etcdctl lease timetolive --keys 694d5765fc71500b
lease 694d5765fc71500b granted with TTL(500s), remaining(132s), attached keys([zoo2 zoo1])