add watch key with prefix
This commit is contained in:
parent
840ca01f87
commit
628eac60b4
@ -11,14 +11,16 @@ import (
|
||||
"context"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
)
|
||||
|
||||
// WatchKey 监听key的变化,永久监听
|
||||
// WatchKeyWithOption ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2:58 下午 2021/11/23
|
||||
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
|
||||
// Date : 2:29 下午 2021/11/26
|
||||
func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
|
||||
if nil == callbackFunc {
|
||||
// 变化之后,没有任何逻辑处理,视为不需要监听变化
|
||||
return
|
||||
@ -35,6 +37,24 @@ func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler)
|
||||
}
|
||||
}
|
||||
|
||||
// WatchKey 监听key的变化,永久监听
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2:58 下午 2021/11/23
|
||||
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
|
||||
WatchKeyWithOption(ctx, watchKey, callbackFunc)
|
||||
}
|
||||
|
||||
// WatchWithKeyPrefix ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2:30 下午 2021/11/26
|
||||
func WatchWithKeyPrefix(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
|
||||
WatchKeyWithOption(ctx, watchKey, callbackFunc, clientv3.WithPrefix())
|
||||
}
|
||||
|
||||
// WatchKeyWithCancel 可以随时取消的
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
Loading…
Reference in New Issue
Block a user