update etcd

This commit is contained in:
2023-08-15 12:56:49 +08:00
parent fcf2830889
commit d6c38ba1c0
11 changed files with 46 additions and 364 deletions

View File

@@ -20,7 +20,7 @@ import (
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:29 下午 2021/11/26
func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
func (wc *WrapperClient) WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
if nil == callbackFunc {
// 变化之后,没有任何逻辑处理,视为不需要监听变化
return
@@ -29,7 +29,7 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
ctx = context.Background()
}
rch := Client.Watch(ctx, watchKey, optionList...) // <-chan WatchResponse
rch := wc.client.Watch(ctx, watchKey, optionList...) // <-chan WatchResponse
for watchResp := range rch {
for _, ev := range watchResp.Events {
callbackFunc(ev)
@@ -42,8 +42,8 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:58 下午 2021/11/23
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
WatchKeyWithOption(ctx, watchKey, callbackFunc)
func (wc *WrapperClient) WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
wc.WatchKeyWithOption(ctx, watchKey, callbackFunc)
}
// WatchWithKeyPrefix ...
@@ -51,8 +51,8 @@ func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler)
// 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())
func (wc *WrapperClient) WatchWithKeyPrefix(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
wc.WatchKeyWithOption(ctx, watchKey, callbackFunc, clientv3.WithPrefix())
}
// WatchKeyWithCancel 可以随时取消的
@@ -60,7 +60,7 @@ func WatchWithKeyPrefix(ctx context.Context, watchKey string, callbackFunc Watch
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:16 下午 2021/11/23
func WatchKeyWithCancel(ctx context.Context, watchKey string, callbackFunc WatcherHandler, cancelChan chan interface{}, cancelDealFunc CancelWatcherHandler) {
func (wc *WrapperClient) WatchKeyWithCancel(ctx context.Context, watchKey string, callbackFunc WatcherHandler, cancelChan chan interface{}, cancelDealFunc CancelWatcherHandler) {
if nil == callbackFunc {
// 变化之后,没有任何逻辑处理,视为不需要监听变化
return
@@ -74,7 +74,7 @@ func WatchKeyWithCancel(ctx context.Context, watchKey string, callbackFunc Watch
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
rch := Client.Watch(context.Background(), watchKey) // <-chan WatchResponse
rch := wc.client.Watch(context.Background(), watchKey) // <-chan WatchResponse
hasFinish := false
for {
@@ -104,7 +104,7 @@ func WatchKeyWithCancel(ctx context.Context, watchKey string, callbackFunc Watch
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:35 下午 2021/11/23
func WatchKeyOnce(ctx context.Context, watchKey string, callbackFunc WatcherHandler, timeout time.Duration, timeoutHandler TimeoutWatcherHandler) {
func (wc *WrapperClient) WatchKeyOnce(ctx context.Context, watchKey string, callbackFunc WatcherHandler, timeout time.Duration, timeoutHandler TimeoutWatcherHandler) {
if nil == callbackFunc {
// 变化之后,没有任何逻辑处理,视为不需要监听变化
return
@@ -123,7 +123,7 @@ func WatchKeyOnce(ctx context.Context, watchKey string, callbackFunc WatcherHand
)
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
rch := wc.client.Watch(ctx, watchKey) // <-chan WatchResponse
select {
case <-time.After(timeout):
if nil != timeoutHandler {