Compare commits
0
Commits
master
..
beae868232
No files matched your search
@@ -20,4 +20,3 @@
|
||||
.vscode
|
||||
mail_test.go
|
||||
*_test.go
|
||||
!client_test.go
|
||||
@@ -196,7 +196,7 @@ func (o *OwnClient) AddClient(instanceFlag string, logger *zap.Logger, instanceC
|
||||
clientInfo.Master = o.newClient(instanceConfig.Master)
|
||||
}
|
||||
if nil != instanceConfig.Slave {
|
||||
clientInfo.Slave = o.newClient(instanceConfig.Slave)
|
||||
clientInfo.Master = o.newClient(instanceConfig.Slave)
|
||||
}
|
||||
o.lock.Lock()
|
||||
defer o.lock.Unlock()
|
||||
@@ -264,7 +264,7 @@ func (o *OwnClient) newClient(instanceConfig *define.Options) *redisClient.Clien
|
||||
DialTimeout: time.Duration(instanceConfig.DialTimeout) * time.Millisecond,
|
||||
ReadTimeout: time.Duration(instanceConfig.ReadTimeout) * time.Millisecond,
|
||||
WriteTimeout: time.Duration(instanceConfig.WriteTimeout) * time.Millisecond,
|
||||
ContextTimeoutEnabled: instanceConfig.ContextTimeoutEnabled,
|
||||
// ContextTimeoutEnabled: instanceConfig.ContextTimeoutEnabled,
|
||||
PoolFIFO: instanceConfig.PoolFIFO,
|
||||
PoolSize: instanceConfig.PoolSize,
|
||||
PoolTimeout: time.Duration(instanceConfig.PoolTimeout) * time.Millisecond,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/redis/define"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func TestAddClientKeepsMasterAndSlaveSeparate(t *testing.T) {
|
||||
client := &OwnClient{
|
||||
lock: &sync.RWMutex{},
|
||||
instanceTable: map[string]*define.ClientInfo{},
|
||||
whiteCommandTable: map[string]bool{},
|
||||
logger: zap.NewNop(),
|
||||
}
|
||||
err := client.AddClient("main", zap.NewNop(), &define.Config{
|
||||
Master: &define.Options{Addr: "master.example:6379"},
|
||||
Slave: &define.Options{Addr: "slave.example:6379"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := client.GetRealClient("main")
|
||||
if info.MasterClient() == nil || info.MasterClient().Options().Addr != "master.example:6379" {
|
||||
t.Fatal("master connection was overwritten")
|
||||
}
|
||||
if info.SlaveClient() == nil || info.SlaveClient().Options().Addr != "slave.example:6379" {
|
||||
t.Fatal("slave connection was not retained")
|
||||
}
|
||||
_ = info.MasterClient().Close()
|
||||
_ = info.SlaveClient().Close()
|
||||
}
|
||||
|
||||
func TestNewClientPassesContextTimeoutEnabled(t *testing.T) {
|
||||
client := &OwnClient{}
|
||||
redisClient := client.newClient(&define.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
ContextTimeoutEnabled: true,
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
_ = redisClient.Close()
|
||||
})
|
||||
|
||||
if !redisClient.Options().ContextTimeoutEnabled {
|
||||
t.Fatal("context timeout option was not passed to go-redis")
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ go 1.24.0
|
||||
toolchain go1.24.2
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260127050054-349cdcde813a
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20260321023345-6c6e467e3a14
|
||||
github.com/go-redis/redismock/v9 v9.2.0
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260127050054-349cdcde813a h1:4apFwfRDdGBkSybcLWzjIYjz8i6yR28Wyt7iBK3K+Po=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260127050054-349cdcde813a/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256 h1:zYkRoH86j+4BoVGCWUY6zA+FIQNmul/c8whmmYK3bT4=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42 h1:VjYrb4adud7FHeiYS9XA0B/tOaJjfRejzQAlwimrrDc=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20260112135254-c9ba29f9f674 h1:75JJ09HPqWi9qm7XD+vV6p5TaCMQgDsae/EbsLiE1t4=
|
||||
|
||||
-31
@@ -111,34 +111,3 @@ func (w *wrapper) BLPop(ctx context.Context, instanceFlag string, key []string,
|
||||
paramList = append(paramList, timeout)
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandBlpop, paramList...)
|
||||
}
|
||||
|
||||
// ZRangeByScore 按分值获取数据
|
||||
func (w *wrapper) ZRangeByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZrangeByScore, key, startScore, endScore, "WITHSCORES")
|
||||
}
|
||||
|
||||
// ZRemRangeByScore 删除集合中分值区间的数据
|
||||
func (w *wrapper) ZRemRangeByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZRemRangeByScore, key, startScore, endScore)
|
||||
}
|
||||
|
||||
// ZRangeAndRemByScore 获取集合到期数据并删除
|
||||
// 本质: ZRange + ZRemRangeByScore
|
||||
func (w *wrapper) ZRangeAndRemByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
rangeRes := w.ZRangeByScore(ctx, instanceFlag, key, startScore, endScore)
|
||||
if nil == rangeRes.Err {
|
||||
// 读取成功, 删除
|
||||
w.ZRemRangeByScore(ctx, instanceFlag, key, startScore, endScore)
|
||||
}
|
||||
return rangeRes
|
||||
}
|
||||
|
||||
// ZAdd ...
|
||||
func (w *wrapper) ZAdd(ctx context.Context, instanceFlag string, key string, score int64, data any) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZadd, key, score, data)
|
||||
}
|
||||
|
||||
// ZAddWithOption ...
|
||||
func (w *wrapper) ZAddWithOption(ctx context.Context, instanceFlag string, key string, option string, score int64, data any) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZadd, key, option, score, data)
|
||||
}
|
||||