mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctlv3: combine Watch, WatchPrefix
This commit is contained in:
parent
a24d276891
commit
7a7751b994
@ -54,7 +54,7 @@ func snapshotToStdout(c *clientv3.Client) {
|
|||||||
// must explicitly fetch first revision since no retry on stdout
|
// must explicitly fetch first revision since no retry on stdout
|
||||||
wapi := clientv3.NewWatcher(c)
|
wapi := clientv3.NewWatcher(c)
|
||||||
defer wapi.Close()
|
defer wapi.Close()
|
||||||
wr := <-wapi.WatchPrefix(context.TODO(), "", 1)
|
wr := <-wapi.Watch(context.TODO(), "", clientv3.WithPrefix(), clientv3.WithRev(1))
|
||||||
if len(wr.Events) > 0 {
|
if len(wr.Events) > 0 {
|
||||||
wr.CompactRevision = 1
|
wr.CompactRevision = 1
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,11 @@ func watchCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
c := mustClientFromCmd(cmd)
|
c := mustClientFromCmd(cmd)
|
||||||
w := clientv3.NewWatcher(c)
|
w := clientv3.NewWatcher(c)
|
||||||
|
|
||||||
var wc clientv3.WatchChan
|
opts := []clientv3.OpOption{clientv3.WithRev(watchRev)}
|
||||||
if !watchPrefix {
|
if watchPrefix {
|
||||||
wc = w.Watch(context.TODO(), args[0], watchRev)
|
opts = append(opts, clientv3.WithPrefix())
|
||||||
} else {
|
|
||||||
wc = w.Watch(context.TODO(), args[0], watchRev)
|
|
||||||
}
|
}
|
||||||
|
wc := w.Watch(context.TODO(), args[0], opts...)
|
||||||
printWatchCh(wc)
|
printWatchCh(wc)
|
||||||
err := w.Close()
|
err := w.Close()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -114,12 +113,11 @@ func watchInteractiveFunc(cmd *cobra.Command, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
key = moreargs[0]
|
key = moreargs[0]
|
||||||
}
|
}
|
||||||
var ch clientv3.WatchChan
|
opts := []clientv3.OpOption{clientv3.WithRev(watchRev)}
|
||||||
if watchPrefix {
|
if watchPrefix {
|
||||||
ch = w.WatchPrefix(context.TODO(), key, watchRev)
|
opts = append(opts, clientv3.WithPrefix())
|
||||||
} else {
|
|
||||||
ch = w.Watch(context.TODO(), key, watchRev)
|
|
||||||
}
|
}
|
||||||
|
ch := w.Watch(context.TODO(), key, opts...)
|
||||||
go printWatchCh(ch)
|
go printWatchCh(ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user