2 changed files with 7 additions and 25 deletions

No files matched your search

+3 -1
View File
@@ -4,6 +4,8 @@ go 1.17
replace github.com/coreos/bbolt v1.3.4 => go.etcd.io/bbolt v1.3.4
replace github.com/gin-gonic/gin v1.7.5 => github.com/gin-gonic/gin v1.7.6
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
require (
@@ -11,7 +13,7 @@ require (
github.com/apolloconfig/agollo/v4 v4.0.9
github.com/coreos/etcd v3.3.27+incompatible
github.com/ddliu/go-httpclient v0.6.9
github.com/gin-gonic/gin v1.7.6
github.com/gin-gonic/gin v1.7.5
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redis_rate/v9 v9.1.2
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
+4 -24
View File
@@ -11,16 +11,14 @@ import (
"context"
"math"
"time"
"go.etcd.io/etcd/clientv3"
)
// WatchKeyWithOption ...
// WatchKey 监听key的变化,永久监听
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:29 下午 2021/11/26
func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
// Date : 2:58 下午 2021/11/23
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
if nil == callbackFunc {
// 变化之后,没有任何逻辑处理,视为不需要监听变化
return
@@ -29,7 +27,7 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
ctx = context.Background()
}
rch := Client.Watch(ctx, watchKey, optionList...) // <-chan WatchResponse
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
for watchResp := range rch {
for _, ev := range watchResp.Events {
callbackFunc(ev)
@@ -37,24 +35,6 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
}
}
// 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<白茶清欢>
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.