From 840f58c3e2a5a2d4db5589f15fa5049e2a6dec74 Mon Sep 17 00:00:00 2001 From: "ali.tu" Date: Mon, 29 Jan 2024 11:51:53 +0800 Subject: [PATCH] feat(redis-cache): add redis cluster support. --- cache/redis.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cache/redis.go b/cache/redis.go index 3852a14..e789f5f 100644 --- a/cache/redis.go +++ b/cache/redis.go @@ -5,14 +5,15 @@ import ( "encoding/json" "errors" "fmt" + "time" + fmt2 "github.com/ArtisanCloud/PowerLibs/v3/fmt" "github.com/ArtisanCloud/PowerLibs/v3/object" "github.com/redis/go-redis/v9" - "time" ) type GRedis struct { - Pool *redis.Client + Pool redis.UniversalClient defaultExpiration time.Duration lockRetries int } @@ -44,9 +45,9 @@ var CTXRedis = context.Background() const lockRetries = 5 -func NewGRedis(opts *redis.Options) (gr *GRedis) { +func NewGRedis(opts *redis.UniversalOptions) (gr *GRedis) { - c := redis.NewClient(opts) + c := redis.NewUniversalClient(opts) gr = &GRedis{ Pool: c, lockRetries: lockRetries, @@ -102,8 +103,8 @@ func (gr *GRedis) SetEx(key string, value interface{}, expires time.Duration) er //fmt.Printf("result:%s \r\n",cmd.String()) //fmt.Printf("err:%s \r\n", cmd.Err()) - connPool := gr.Pool.Conn() - cmd := connPool.SetEx(CTXRedis, key, mValue, expires) + // connPool := gr.Pool.Conn() + cmd := gr.Pool.SetEx(CTXRedis, key, mValue, expires) //fmt2.Dump(connPool.Pipeline()) //fmt.Printf("result:", cmd.String())