Compare commits

..
0 Commits
14 changed files with 756 additions and 446 deletions

No files matched your search

-1
View File
@@ -20,4 +20,3 @@
.vscode .vscode
mail_test.go mail_test.go
*_test.go *_test.go
!client_test.go
+8 -11
View File
@@ -10,9 +10,8 @@ package abstract
import ( import (
"context" "context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/redis/define" "git.zhangdeman.cn/zhangdeman/redis/define"
"github.com/go-redis/redismock/v9" "github.com/go-redis/redis/v8"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -22,13 +21,11 @@ import (
// //
// Date : 15:09 2024/6/18 // Date : 15:09 2024/6/18
type IRedisClient interface { type IRedisClient interface {
GetRealClient(instanceFlag string) *define.ClientInfo // 获取客户端连接 GetRealClient(instanceFlag string) *redis.ClusterClient // 获取客户端连接
GetRealClientWithError(instanceFlag string) (*define.ClientInfo, error) // 获取带error的客户端连接 GetRealClientWithError(instanceFlag string) (*redis.ClusterClient, error) // 获取带error的客户端连接
AddClient(instanceFlag string, logger *zap.Logger, instanceConfig *define.Config) error // 添加新的客户端连接 AddClient(instanceFlag string, instanceConfig *define.ClusterOptions) error // 添加新的客户端连接
RemoveClient(instanceFlag string) // 移除一个客户端连接 RemoveClient(instanceFlag string) // 移除一个客户端连接
SetLogger(loggerInstance *zap.Logger, extraLogFieldList []string) // 设置日志实例, 全局生效, 而非针对某一个实例 SetLogger(loggerInstance *zap.Logger) // 设置日志实例, 全局生效, 而非针对某一个实例
Exec(ctx context.Context, instanceFlag string, command consts.RedisCmd, args ...any) *define.RedisResult // 执行任意命令 Exec(ctx context.Context, instanceFlag string, command string, args ...any) *define.RedisResult // 执行任意命令
SetCommandWhiteList(command []consts.RedisCmd) // 设置命令的白名单,全局生效, 而非单独针对某一个实例 SetCommandWhiteList(command []string) // 设置命令的白名单,全局生效, 而非单独针对某一个实例
SetMockMode() // 设置mock模式, 这是单元测试专用的, 生产环境不要使用!!!!!!
GetMockInstance() redismock.ClientMock // 数据mock实例
} }
+37
View File
@@ -0,0 +1,37 @@
// Package apply ...
//
// Description : apply ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-02-13 11:24
package apply
import (
"git.zhangdeman.cn/zhangdeman/redis"
)
var (
// Cache 数据缓存的场景
Cache *cache
)
type cache struct {
}
// Set 设置缓存
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:28 2023/2/13
func (c *cache) Set(ctx *redis.Context, key string, value interface{}) error {
var (
err error
rc *redis.RealClient
)
if rc, err = redis.Client.GetRedisClientWithError(ctx.Flag); nil != err {
return err
}
return rc.Master.Set(nil, key, value, -1).Err()
}
+77 -159
View File
@@ -13,15 +13,11 @@ import (
"sync" "sync"
"time" "time"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/wrapper/op_any"
"git.zhangdeman.cn/zhangdeman/wrapper/op_array"
"github.com/go-redis/redismock/v9"
"git.zhangdeman.cn/zhangdeman/redis/abstract" "git.zhangdeman.cn/zhangdeman/redis/abstract"
"git.zhangdeman.cn/zhangdeman/redis/define" "git.zhangdeman.cn/zhangdeman/redis/define"
wrapperOperate "git.zhangdeman.cn/zhangdeman/wrapper"
redisClient "github.com/go-redis/redis/v8"
"github.com/pkg/errors" "github.com/pkg/errors"
redisClient "github.com/redis/go-redis/v9"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -32,21 +28,16 @@ var (
func init() { func init() {
Client = &OwnClient{ Client = &OwnClient{
lock: &sync.RWMutex{}, lock: &sync.RWMutex{},
instanceTable: make(map[string]*define.ClientInfo), instanceTable: make(map[string]*redisClient.ClusterClient),
whiteCommandTable: make(map[string]bool), whiteCommandTable: make(map[string]bool),
logger: zap.NewNop(),
} }
} }
type OwnClient struct { type OwnClient struct {
lock *sync.RWMutex lock *sync.RWMutex
instanceTable map[string]*define.ClientInfo instanceTable map[string]*redisClient.ClusterClient
whiteCommandTable map[string]bool whiteCommandTable map[string]bool
logger *zap.Logger logger *zap.Logger
extraLogFieldList []string
mockMode bool
mockInstance redismock.ClientMock
mockClient *redisClient.Client
} }
func (o *OwnClient) isAllowCommand(command string) bool { func (o *OwnClient) isAllowCommand(command string) bool {
@@ -65,66 +56,49 @@ func (o *OwnClient) isAllowCommand(command string) bool {
} }
// Exec 执行命令 // Exec 执行命令
func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command consts.RedisCmd, args ...any) *define.RedisResult { //
if nil == ctx { // Author : go_developer@163.com<白茶清欢>
ctx = context.Background() //
} // Date : 11:05 2024/6/19
func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command string, args ...any) *define.RedisResult {
var ( var (
instance *define.ClientInfo instance *redisClient.ClusterClient
) )
cmdParamList := []any{ cmdParamList := []any{
strings.ToLower(command.String()), // redis 命令不区分大小写, 统一使用小写 command,
} }
argStrList := make([]string, 0) argStrList := make([]string, 0)
for _, itemArg := range args { for _, itemArg := range args {
argStrList = append(argStrList, op_any.AnyDataType(itemArg).ToString()) argStrList = append(argStrList, wrapperOperate.AnyDataType(itemArg).ToString().Value())
cmdParamList = append(cmdParamList, itemArg) cmdParamList = append(cmdParamList, itemArg)
} }
res := &define.RedisResult{ res := &define.RedisResult{
StartTime: time.Now().UnixMilli(), StartTime: time.Now().UnixMilli(),
FinishTime: 0, FinishTime: 0,
UsedTime: 0, UsedTime: 0,
Result: "", Result: "",
Command: command, Command: command,
ArgList: argStrList, ArgList: argStrList,
Err: nil, Err: nil,
InstanceFlag: instanceFlag,
} }
defer func() { defer func() {
res.FinishTime = time.Now().UnixMilli() res.FinishTime = time.Now().UnixMilli()
res.UsedTime = res.FinishTime - res.StartTime res.UsedTime = res.FinishTime - res.StartTime
logDataList := []zap.Field{ if nil == o.logger {
// 未注入日志实例
return
}
o.logger.Info(
"Redis命令执行记录",
zap.Int64("start_time", res.StartTime), zap.Int64("start_time", res.StartTime),
zap.Int64("finish_time", res.FinishTime), zap.Int64("finish_time", res.FinishTime),
zap.Int64("used_time", res.UsedTime), zap.Int64("used_time", res.UsedTime),
zap.String("command", res.Command.String()), zap.String("command", res.Command),
zap.String("arg_list", strings.Join(res.ArgList, " ")), zap.String("arg_list", strings.Join(res.ArgList, " ")),
zap.String("execute_result", res.Result), zap.String("execute_result", res.Result),
zap.Error(res.Err), zap.Error(res.Err),
} )
for _, item := range o.extraLogFieldList {
logDataList = append(logDataList, zap.Any(item, ctx.Value(item)))
}
isError := false
if res.Err != nil && res.Err != redisClient.Nil {
isError = true
}
loggerInstance := o.logger
if nil != instance && nil != instance.Logger {
loggerInstance = instance.Logger
}
if isError {
loggerInstance.Error(
"Redis 命令执行失败",
logDataList...,
)
} else {
loggerInstance.Info(
"Redis 命令执行成功",
logDataList...,
)
}
}() }()
if instance, res.Err = o.GetRealClientWithError(instanceFlag); nil != res.Err { if instance, res.Err = o.GetRealClientWithError(instanceFlag); nil != res.Err {
return res return res
@@ -132,44 +106,34 @@ func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command const
if nil == ctx { if nil == ctx {
ctx = context.Background() ctx = context.Background()
} }
if instance.ReadOnly && o.isWriteCommand(command) { cmdRes := instance.Do(ctx, cmdParamList...)
// 只读实例, 尝试执行写命令
res.Err = errors.New(instanceFlag + " : instance is read only")
return res
}
if instance.ReadOnly && o.isWriteCommand(command) && instance.MasterClient() == nil {
// 写命令, 没有主库连接
res.Err = errors.New(instanceFlag + " : instance master client is nil")
return res
}
redisRealClient := instance.MasterClient()
if !o.isWriteCommand(command) {
redisRealClient = instance.SlaveClient()
}
cmdRes := redisRealClient.Do(ctx, cmdParamList...)
if res.Err = cmdRes.Err(); nil != res.Err { if res.Err = cmdRes.Err(); nil != res.Err {
return res return res
} }
res.Result = op_any.AnyDataType(cmdRes.Val()).ToString() res.Result = cmdRes.String()
return res return res
} }
// SetCommandWhiteList 设置命令白名单, 空 或者 包含 * 则认为所有命令均允许执行 // SetCommandWhiteList 设置命令白名单, 空 或者 包含 * 则认为所有命令均允许执行
func (o *OwnClient) SetCommandWhiteList(commandList []consts.RedisCmd) { //
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:02 2024/6/19
func (o *OwnClient) SetCommandWhiteList(commandList []string) {
o.lock.Lock() o.lock.Lock()
defer o.lock.Unlock() defer o.lock.Unlock()
for _, itemCommand := range commandList { for _, itemCommand := range commandList {
o.whiteCommandTable[strings.ToLower(strings.TrimSpace(itemCommand.String()))] = true o.whiteCommandTable[strings.ToLower(strings.TrimSpace(itemCommand))] = true
} }
} }
func (o *OwnClient) GetRealClient(instanceFlag string) *define.ClientInfo { func (o *OwnClient) GetRealClient(instanceFlag string) *redisClient.ClusterClient {
o.lock.RLock() o.lock.RLock()
defer o.lock.RUnlock() defer o.lock.RUnlock()
return o.instanceTable[instanceFlag] return o.instanceTable[instanceFlag]
} }
func (o *OwnClient) GetRealClientWithError(instanceFlag string) (*define.ClientInfo, error) { func (o *OwnClient) GetRealClientWithError(instanceFlag string) (*redisClient.ClusterClient, error) {
o.lock.RLock() o.lock.RLock()
defer o.lock.RUnlock() defer o.lock.RUnlock()
instance, exist := o.instanceTable[instanceFlag] instance, exist := o.instanceTable[instanceFlag]
@@ -179,28 +143,47 @@ func (o *OwnClient) GetRealClientWithError(instanceFlag string) (*define.ClientI
return instance, nil return instance, nil
} }
func (o *OwnClient) AddClient(instanceFlag string, logger *zap.Logger, instanceConfig *define.Config) error { func (o *OwnClient) AddClient(instanceFlag string, instanceConfig *define.ClusterOptions) error {
if nil == instanceConfig.Master && !instanceConfig.ReadOnly { instance := redisClient.NewClusterClient(&redisClient.ClusterOptions{
// 不是只读, 则要求 主库配置 和 从库配置都要存在 Addrs: instanceConfig.Addrs,
return errors.New(instanceFlag + " : master config is nil") // ClientName: instanceConfig.ClientName,
} NewClient: nil,
MaxRedirects: instanceConfig.MaxRedirects,
clientInfo := &define.ClientInfo{ ReadOnly: instanceConfig.ReadOnly,
Logger: logger, RouteByLatency: instanceConfig.RouteByLatency,
ReadOnly: instanceConfig.ReadOnly, RouteRandomly: instanceConfig.RouteRandomly,
Master: nil, ClusterSlots: nil,
Slave: nil, Dialer: nil,
} OnConnect: func(ctx context.Context, cn *redisClient.Conn) error {
return nil
if nil != instanceConfig.Master { },
clientInfo.Master = o.newClient(instanceConfig.Master) // Protocol: 0,
} Username: instanceConfig.Username,
if nil != instanceConfig.Slave { Password: instanceConfig.Password,
clientInfo.Slave = o.newClient(instanceConfig.Slave) // CredentialsProvider: nil,
} // CredentialsProviderContext: nil,
MaxRetries: instanceConfig.MaxRetries,
MinRetryBackoff: time.Duration(instanceConfig.MinRetryBackoff) * time.Millisecond,
MaxRetryBackoff: time.Duration(instanceConfig.MaxRetryBackoff) * time.Millisecond,
DialTimeout: time.Duration(instanceConfig.DialTimeout) * time.Millisecond,
ReadTimeout: time.Duration(instanceConfig.ReadTimeout) * time.Millisecond,
WriteTimeout: time.Duration(instanceConfig.WriteTimeout) * time.Millisecond,
// ContextTimeoutEnabled: instanceConfig.ContextTimeoutEnabled,
PoolFIFO: instanceConfig.PoolFIFO,
PoolSize: instanceConfig.PoolSize,
PoolTimeout: time.Duration(instanceConfig.PoolTimeout) * time.Millisecond,
MinIdleConns: instanceConfig.MinIdleConn,
// MaxIdleConns: instanceConfig.MaxIdleConn,
// MaxActiveConns: instanceConfig.MaxActiveConn,
// ConnMaxIdleTime: time.Duration(instanceConfig.ConnMaxIdleTime) * time.Second,
// ConnMaxLifetime: time.Duration(instanceConfig.ConnMaxIdleTime) * time.Second,
TLSConfig: nil,
// DisableIndentity: instanceConfig.DisableIdentity,
// IdentitySuffix: instanceConfig.IdentitySuffix,
})
o.lock.Lock() o.lock.Lock()
defer o.lock.Unlock() defer o.lock.Unlock()
o.instanceTable[instanceFlag] = clientInfo o.instanceTable[instanceFlag] = instance
return nil return nil
} }
@@ -210,71 +193,6 @@ func (o *OwnClient) RemoveClient(instanceFlag string) {
delete(o.instanceTable, instanceFlag) delete(o.instanceTable, instanceFlag)
} }
func (o *OwnClient) SetLogger(loggerInstance *zap.Logger, extraLogFieldList []string) { func (o *OwnClient) SetLogger(loggerInstance *zap.Logger) {
o.logger = loggerInstance o.logger = loggerInstance
o.extraLogFieldList = extraLogFieldList
}
// isWriteCommand 判断是否写命令
func (o *OwnClient) isWriteCommand(command consts.RedisCmd) bool {
return op_array.ArrayType[string]([]string{
consts.RedisCommandDel.String(),
consts.RedisCommandSet.String(),
consts.RedisCommandLpush.String(),
consts.RedisCommandRpush.String(),
consts.RedisCommandMSet.String(),
consts.RedisCommandPublish.String(),
consts.RedisCommandPsubScribe.String(),
}).Has(strings.ToUpper(command.String())) >= 0
}
// SetMockMode 启用mock, 非单元测试不要使用!!!!!!!!
func (o *OwnClient) SetMockMode() {
o.mockMode = true
o.mockClient, o.mockInstance = redismock.NewClientMock()
}
// GetMockInstance 获取mock实例
func (o *OwnClient) GetMockInstance() redismock.ClientMock {
return o.mockInstance
}
// newClient 获取客户端连接
func (o *OwnClient) newClient(instanceConfig *define.Options) *redisClient.Client {
if o.mockMode {
// mock模式下, 直接返回mock实例
return o.mockClient
}
return redisClient.NewClient(&redisClient.Options{
DB: instanceConfig.DB,
Addr: instanceConfig.Addr,
ClientName: instanceConfig.ClientName,
Dialer: nil,
OnConnect: func(ctx context.Context, cn *redisClient.Conn) error {
return nil
},
// Protocol: 0,
Username: instanceConfig.Username,
Password: instanceConfig.Password,
// CredentialsProvider: nil,
// CredentialsProviderContext: nil,
MaxRetries: instanceConfig.MaxRetries,
MinRetryBackoff: time.Duration(instanceConfig.MinRetryBackoff) * time.Millisecond,
MaxRetryBackoff: time.Duration(instanceConfig.MaxRetryBackoff) * time.Millisecond,
DialTimeout: time.Duration(instanceConfig.DialTimeout) * time.Millisecond,
ReadTimeout: time.Duration(instanceConfig.ReadTimeout) * time.Millisecond,
WriteTimeout: time.Duration(instanceConfig.WriteTimeout) * time.Millisecond,
ContextTimeoutEnabled: instanceConfig.ContextTimeoutEnabled,
PoolFIFO: instanceConfig.PoolFIFO,
PoolSize: instanceConfig.PoolSize,
PoolTimeout: time.Duration(instanceConfig.PoolTimeout) * time.Millisecond,
MinIdleConns: instanceConfig.MinIdleConn,
// MaxIdleConns: instanceConfig.MaxIdleConn,
// MaxActiveConns: instanceConfig.MaxActiveConn,
// ConnMaxIdleTime: time.Duration(instanceConfig.ConnMaxIdleTime) * time.Second,
// ConnMaxLifetime: time.Duration(instanceConfig.ConnMaxIdleTime) * time.Second,
TLSConfig: nil,
// DisableIndentity: instanceConfig.DisableIdentity,
// IdentitySuffix: instanceConfig.IdentitySuffix,
})
} }
-49
View File
@@ -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")
}
}
+149
View File
@@ -0,0 +1,149 @@
// Package redis ...
//
// Description : redis ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-06-15 11:52
package redis
import (
"fmt"
"time"
"github.com/go-redis/redis/v8"
"git.zhangdeman.cn/zhangdeman/logger"
)
// FullConfig 完整配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:23 2022/6/15
type FullConfig struct {
ExtraFieldList []string `json:"extra_field_list" yaml:"extra_field_list"` // 从上下文抽取的字段信息
Logger *logger.InputLogConfig `json:"logger" yaml:"logger"` // 日志配置
Master *Config `json:"master" yaml:"master"` // 主节点
Slave *Config `json:"slave" yaml:"slave"` // 从节点
}
// Config redis的配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:52 2022/6/15
type Config struct {
Network string `json:"network" yaml:"network"` // 连接方式 tcp 或 unix , 默认 tcp
Host string `yaml:"host" json:"host"` // 地址
Port int `yaml:"port" json:"port"` // 端口
// Dialer creates new network connection and has priority over
// Network and Addr options.
// Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
// Hook that is called when new connection is established.
// OnConnect func(ctx context.Context, cn *redis.Conn) error
// Use the specified Username to authenticate the current connection
// with one of the connections defined in the ACL list when connecting
// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
Username string `json:"username" yaml:"username"` // 账号
// Optional password. Must match the password specified in the
// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
// or the User Password when connecting to a Redis 6.0 instance, or greater,
// that is using the Redis ACL system.
Password string `json:"password" yaml:"password"` // 密码
// Database to be selected after connecting to the server.
DB int `json:"db" yaml:"db"` // 选中的数据库
// Maximum number of retries before giving up.
// Default is 3 retries; -1 (not 0) disables retries.
MaxRetries int `json:"max_retries" yaml:"max_retries"` // 最大重试次数, 默认 3 , -1 为不重试
// Minimum backoff between each retry.
// Default is 8 milliseconds; -1 disables backoff.
MinRetryBackoff int64 `json:"min_retry_backoff" yaml:"min_retry_backoff"` // 最小重试的时间间隔, 默认 8ms, -1禁用
// Maximum backoff between each retry.
// Default is 512 milliseconds; -1 disables backoff.
MaxRetryBackoff int `json:"max_retry_backoff" yaml:"max_retry_backoff"` // 最大重试的时间间隔, 默认 512ms, -1禁用
// Dial timeout for establishing new connections.
// Default is 5 seconds.
DialTimeout int64 `json:"dial_timeout" yaml:"dial_timeout"` // 建立新连接的超时时间, 默认 5s
// Timeout for socket reads. If reached, commands will fail
// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
// Default is 3 seconds.
ReadTimeout int64 `json:"read_timeout" yaml:"read_timeout"` // 读取超时时间,默认 3s , -1 不设置超时
// Timeout for socket writes. If reached, commands will fail
// with a timeout instead of blocking.
// Default is ReadTimeout.
WriteTimeout int64 `json:"write_timeout" yaml:"write_timeout"` // 写入超时时间, 默认值和 ReadTimeout 配置一致
// Type of connection pool.
// true for FIFO pool, false for LIFO pool.
// Note that fifo has higher overhead compared to lifo.
PoolFIFO bool `json:"pool_fifo" yaml:"pool_fifo"` // 连接吃采用 FIFO
// Maximum number of socket connections.
// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
PoolSize int `json:"pool_size" yaml:"pool_size"` // 连接池大小, 默认 runtime.GOMAXPROCS * 10
// Minimum number of idle connections which is useful when establishing
// new connection is slow.
MinIdleConns int `json:"min_idle_conns" yaml:"min_idle_conns"` // 最小的 空闲 连接数数量
// Connection age at which client retires (closes) the connection.
// Default is to not close aged connections.
MaxConnAge int64 `json:"max_conn_age" yaml:"max_conn_age"` // 连接最大的存活时常
// Amount of time client waits for connection if all connections
// are busy before returning an error.
// Default is ReadTimeout + 1 second.
PoolTimeout int64 `json:"pool_timeout" yaml:"pool_timeout"` // 连接池无可用连接, 等待的时常, 默认值 ReadTimeout + 1
// Amount of time after which client closes idle connections.
// Should be less than server's timeout.
// Default is 5 minutes. -1 disables idle timeout check.
IdleTimeout int64 `json:"idle_timeout" yaml:"idle_timeout"` // 空闲链接的超时时间, 默认 5 分钟 -1 金童
// Frequency of idle checks made by idle connections reaper.
// Default is 1 minute. -1 disables idle connections reaper,
// but idle connections are still discarded by the client
// if IdleTimeout is set.
IdleCheckFrequency int64 `json:"idle_check_frequency" yaml:"idle_check_frequency"` // 空闲连接检查频率, 默认 1 分钟, -1 禁用, 注意 : 即使禁用,超过 IdleTimeout 时常的连接也不可被读取到
}
// Config2Options 将 自定义的配置文件转为 redis 包需要的配置格式
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:37 2022/6/15
func Config2Options(cfg *Config) *redis.Options {
option := &redis.Options{
Network: cfg.Network,
Addr: fmt.Sprintf("%v:%v", cfg.Host, cfg.Port),
Username: cfg.Username,
Password: cfg.Password,
DB: cfg.DB,
MaxRetries: cfg.MaxRetries,
MinRetryBackoff: time.Duration(cfg.MinRetryBackoff) * time.Millisecond,
MaxRetryBackoff: time.Duration(cfg.MaxRetryBackoff) * time.Millisecond,
DialTimeout: time.Duration(cfg.DialTimeout) * time.Millisecond,
ReadTimeout: time.Duration(cfg.ReadTimeout) * time.Millisecond,
WriteTimeout: time.Duration(cfg.WriteTimeout) * time.Millisecond,
PoolFIFO: cfg.PoolFIFO,
PoolSize: cfg.PoolSize,
MinIdleConns: cfg.MinIdleConns,
MaxConnAge: time.Duration(cfg.MaxConnAge) * time.Millisecond,
PoolTimeout: time.Duration(cfg.PoolTimeout) * time.Millisecond,
IdleTimeout: time.Duration(cfg.IdleTimeout) * time.Millisecond,
IdleCheckFrequency: time.Duration(cfg.IdleCheckFrequency) * time.Millisecond,
TLSConfig: nil,
Limiter: nil,
}
if len(option.Network) == 0 {
option.Network = NetworkTypeTCP
}
return option
}
const (
// NetworkTypeTCP ...
NetworkTypeTCP = "tcp"
// NetworkTypeUnix ...
NetworkTypeUnix = "unix"
)
+141
View File
@@ -0,0 +1,141 @@
// Package redis...
//
// Description : redis...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-02-27 8:22 下午
package redis
import (
"context"
"git.zhangdeman.cn/zhangdeman/easymap"
"github.com/gin-gonic/gin"
)
const (
// 默认的 request_id 字段名
defaultRequestIDField = "request_id"
// 默认的message
defaultMessage = "执行redis命令日志记录"
// 耗时字段
defaultUsedTimeField = "used_field"
// 默认的命令字段
defaultCommandField = "command"
// 默认记录 redis标识的字段
defaultFlagField = "flag"
)
// Context 请求上下文
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:25 下午 2021/2/27
type Context struct {
Flag string // 哪个模块的上下文
Ctx context.Context // ctx
GinCtx *gin.Context // http 请求绑定的gin.context
RequestIDField string // requestID 字段名
RequestID string // requestID 此字段有值, 直接使用此值,无值, 去GinCtx 中读取 RequestIDField
Extra easymap.EasyMap // 扩展信息
}
// NewContext 生成一个上下文
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:26 下午 2021/2/27
func NewContext(flag string, of ...SetContextFunc) *Context {
ctx := &Context{
Flag: flag,
Ctx: nil,
GinCtx: nil,
RequestIDField: "",
RequestID: "",
Extra: nil,
}
for _, f := range of {
f(ctx)
}
if nil == ctx.Ctx {
ctx.Ctx = context.Background()
}
if len(ctx.RequestIDField) == 0 {
ctx.RequestIDField = defaultRequestIDField
}
if nil == ctx.Extra {
ctx.Extra = easymap.NewNormal()
}
// requestID 填充
if len(ctx.RequestID) == 0 {
// 先从 gin 读
if nil != ctx.GinCtx {
ctx.RequestID = ctx.GinCtx.GetString(ctx.RequestIDField)
}
// 再从extra读取
if len(ctx.RequestID) == 0 {
ctx.RequestID, _ = ctx.Extra.GetString(ctx.RequestID)
}
}
return ctx
}
// SetContextFunc 设置context参数
type SetContextFunc func(rc *Context)
// WithCtx 设置context
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:30 下午 2021/2/27
func WithCtx(ctx context.Context) SetContextFunc {
return func(rc *Context) {
rc.Ctx = ctx
}
}
// WithGinCtx 设置gin上下文
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:34 下午 2021/2/27
func WithGinCtx(ginCtx *gin.Context) SetContextFunc {
return func(rc *Context) {
rc.GinCtx = ginCtx
}
}
// WithExtra 设置扩展信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:36 下午 2021/2/27
func WithExtra(extra easymap.EasyMap) SetContextFunc {
return func(rc *Context) {
rc.Extra = extra
}
}
// WithRequestIDField 设置request_id参数名
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:41 下午 2021/2/27
func WithRequestIDField(requestIDField string) SetContextFunc {
return func(rc *Context) {
rc.RequestIDField = requestIDField
}
}
// WithRequestID ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:42 下午 2021/2/27
func WithRequestID(requestID string) SetContextFunc {
return func(rc *Context) {
rc.RequestID = requestID
}
}
+14 -43
View File
@@ -7,18 +7,23 @@
// Date : 2024-06-18 16:12 // Date : 2024-06-18 16:12
package define package define
import ( type ClusterOptions struct {
redisClient "github.com/redis/go-redis/v9"
"go.uber.org/zap"
)
type Options struct {
DB int `json:"db" yaml:"db" ini:"db" toml:"db"` // 选择的数据库序号
Network string `json:"network" yaml:"network" ini:"network" toml:"network"` // 网络连接方式
// A seed list of host:port addresses of cluster nodes. // A seed list of host:port addresses of cluster nodes.
Addr string `json:"addr" yaml:"addr" ini:"addr" toml:"addr"` // 集群IP列表 Addrs []string `json:"addrs" yaml:"addrs" ini:"addrs" toml:"addrs"` // 集群IP列表
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn. // ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
ClientName string `json:"client_name" yaml:"client_name" ini:"client_name" toml:"client_name"` // 集群名称 ClientName string `json:"client_name" yaml:"client_name" ini:"client_name" toml:"client_name"` // 集群名称
// The maximum number of retries before giving up. Command is retried
// on network errors and MOVED/ASK redirects.
// Default is 3 retries.
MaxRedirects int `json:"max_redirects" yaml:"max_redirects" ini:"max_redirects" toml:"max_redirects"` // 最大重试次数
// Enables read-only commands on slave nodes.
ReadOnly bool `json:"read_only" yaml:"read_only" ini:"read_only" toml:"read_only"` // 只读
// Allows routing read-only commands to the closest master or slave node.
// It automatically enables ReadOnly.
RouteByLatency bool `json:"route_by_latency" yaml:"route_by_latency" ini:"route_by_latency" toml:"route_by_latency"`
// Allows routing read-only commands to the random master or slave node.
// It automatically enables ReadOnly.
RouteRandomly bool `json:"route_randomly" yaml:"route_randomly" ini:"route_randomly" toml:"route_randomly"`
Protocol int Protocol int
Username string `json:"username" yaml:"username" ini:"username" toml:"username"` Username string `json:"username" yaml:"username" ini:"username" toml:"username"`
@@ -46,37 +51,3 @@ type Options struct {
IdentitySuffix string `json:"identity_suffix" yaml:"identity_suffix" ini:"identity_suffix" toml:"identity_suffix"` // Add suffix to client name. Default is empty. IdentitySuffix string `json:"identity_suffix" yaml:"identity_suffix" ini:"identity_suffix" toml:"identity_suffix"` // Add suffix to client name. Default is empty.
} }
// Config 数据库连接配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:59 2024/10/8
type Config struct {
ReadOnly bool `json:"readonly" yaml:"readonly" ini:"readonly" toml:"readonly"`
Master *Options `json:"master" yaml:"master" ini:"master" toml:"master"` // 主库配置
Slave *Options `json:"slave" yaml:"slave" ini:"slave" toml:"slave"` // 主库配置
}
// ClientInfo 客户端连接信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:06 2024/10/8
type ClientInfo struct {
Logger *zap.Logger // 日志实例
ReadOnly bool // 是否只读
Master *redisClient.Client // 主库连接
Slave *redisClient.Client // 从库连接
}
func (cf *ClientInfo) MasterClient() *redisClient.Client {
return cf.Master
}
func (cf *ClientInfo) SlaveClient() *redisClient.Client {
if nil != cf.Slave {
return cf.Slave
}
return cf.Master
}
+8 -10
View File
@@ -7,20 +7,18 @@
// Date : 2024-06-19 10:49 // Date : 2024-06-19 10:49
package define package define
import "git.zhangdeman.cn/zhangdeman/consts"
// RedisResult redis名玲玲执行结果 // RedisResult redis名玲玲执行结果
// //
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 10:50 2024/6/19 // Date : 10:50 2024/6/19
type RedisResult struct { type RedisResult struct {
InstanceFlag string `json:"instance_flag"` // 实例标识 InstanceFlag string `json:"instance_flag"` // 实例标识
StartTime int64 `json:"start_time"` // 开始执行时间, 单位 : ms StartTime int64 `json:"start_time"` // 开始执行时间, 单位 : ms
FinishTime int64 `json:"finish_time"` // 完成执行时间, 单位 : ms FinishTime int64 `json:"finish_time"` // 完成执行时间, 单位 : ms
UsedTime int64 `json:"used_time"` // 执行耗时, 单位 : ms UsedTime int64 `json:"used_time"` // 执行耗时, 单位 : ms
Result string `json:"result"` // 执行结果 Result string `json:"result"` // 执行结果
Command consts.RedisCmd `json:"command"` // 执行的命令 Command string `json:"command"` // 执行的命令
ArgList []string `json:"arg_list"` // 参数列表 ArgList []string `json:"arg_list"` // 参数列表
Err error `json:"-"` // 失败信息 Err error `json:"-"` // 失败信息
} }
+43 -18
View File
@@ -1,34 +1,59 @@
module git.zhangdeman.cn/zhangdeman/redis module git.zhangdeman.cn/zhangdeman/redis
go 1.24.0 go 1.21
toolchain go1.24.2 toolchain go1.21.5
require ( require (
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256 git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a git.zhangdeman.cn/zhangdeman/logger v0.0.0-20240308024848-54993a0ed4a6
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20260321023345-6c6e467e3a14 git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e
github.com/go-redis/redismock/v9 v9.2.0 git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000
github.com/gin-gonic/gin v1.10.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-redis/redis_rate/v9 v9.1.2
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.18.0 go.uber.org/zap v1.27.0
go.uber.org/zap v1.27.1
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
require ( require (
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42 // indirect git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240617073616-39e82fd033ed // indirect
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20260112135254-c9ba29f9f674 // indirect git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd // indirect
github.com/BurntSushi/toml v1.6.0 // indirect github.com/BurntSushi/toml v1.4.0 // indirect
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/bytedance/sonic v1.11.8 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mozillazg/go-pinyin v0.21.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/sbabiv/xml2map v1.2.1 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-pinyin v0.20.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/tidwall/match v1.2.0 // indirect github.com/ugorji/go/codec v1.2.12 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect
gopkg.in/ini.v1 v1.67.1 // indirect golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
) )
+108 -64
View File
@@ -1,23 +1,29 @@
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260127050054-349cdcde813a h1:4apFwfRDdGBkSybcLWzjIYjz8i6yR28Wyt7iBK3K+Po= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240617073616-39e82fd033ed h1:BGv+y6ZdtkxI4HeSIHun0QRrIzjLnUht0bKdyO2t6n4=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260127050054-349cdcde813a/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240617073616-39e82fd033ed/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256 h1:zYkRoH86j+4BoVGCWUY6zA+FIQNmul/c8whmmYK3bT4= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260413082525-fb90982b1256/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42 h1:VjYrb4adud7FHeiYS9XA0B/tOaJjfRejzQAlwimrrDc= git.zhangdeman.cn/zhangdeman/logger v0.0.0-20240308024848-54993a0ed4a6 h1:KeRD+IMkzk5RcHyJijT7tLRKW4wtulGcpG1dkKSr/5A=
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI= git.zhangdeman.cn/zhangdeman/logger v0.0.0-20240308024848-54993a0ed4a6/go.mod h1:IpTqawATar71MlLpheQAWrsXMqV2AxoZ3e0Vp3MeHNs=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20260112135254-c9ba29f9f674 h1:75JJ09HPqWi9qm7XD+vV6p5TaCMQgDsae/EbsLiE1t4= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20260112135254-c9ba29f9f674/go.mod h1:EXrvDs830GzqhDNTR5TgKVbT3ADRgyUb2pFerwF4rLc= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd/go.mod h1:6+7whkCmb4sJDIfH3HxNuXRveaM0gCCNWd2uXZqNtIE=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a h1:IGUsWz204BTQlD2l4kenlwJQS4Av2RS2kfUHZ5QVrmw= git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a/go.mod h1:OKI+RVVfRTUf/ox9uDMydtos2YDFr+/UuU4FFZKgPYY= git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20260321023345-6c6e467e3a14 h1:YtOciqKZVCtGt5YMMDEmINzRXK3ZE9mscXSkSKwK8/o= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000 h1:ulssHpUMNoxws/fdJD+bhw8tuMPXp+jB54WwLdJNTsU=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20260321023345-6c6e467e3a14/go.mod h1:oSmLgHs4EausBSmH4GdpGUtjubPek8hLXTAUc4cPCb0= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000/go.mod h1:rt9wlUf/Y6lpZBXb0KK8n0JxEbI1J5JB73XgQmGHJqw=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -25,81 +31,119 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-redis/redismock/v9 v9.2.0 h1:ZrMYQeKPECZPjOj5u9eyOjg8Nnb0BS9lkVIZ6IpsKLw= github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
github.com/go-redis/redismock/v9 v9.2.0/go.mod h1:18KHfGDK4Y6c2R0H38EUGWAdc7ZQS9gfYxc94k7rWT0= github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-redis/redis_rate/v9 v9.1.2 h1:H0l5VzoAtOE6ydd38j8MCq3ABlGLnvvbA1xDSVVCHgQ=
github.com/go-redis/redis_rate/v9 v9.1.2/go.mod h1:oam2de2apSgRG8aJzwJddXbNu91Iyz1m8IKJE2vpvlQ=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mozillazg/go-pinyin v0.21.0 h1:Wo8/NT45z7P3er/9YSLHA3/kjZzbLz5hR7i+jGeIGao= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/mozillazg/go-pinyin v0.21.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs=
github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0=
github.com/sbabiv/xml2map v1.2.1 h1:1lT7t0hhUvXZCkdxqtq4n8/ZCnwLWGq4rDuDv5XOoFE=
github.com/sbabiv/xml2map v1.2.1/go.mod h1:2TPoAfcaM7+Sd4iriPvzyntb2mx7GY+kkQpB/GQa/eo=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
gopkg.in/ini.v1 v1.67.1/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
+16 -15
View File
@@ -12,9 +12,10 @@ import (
"strings" "strings"
"git.zhangdeman.cn/zhangdeman/util" "git.zhangdeman.cn/zhangdeman/util"
redisClient "github.com/redis/go-redis/v9"
yml "gopkg.in/yaml.v3" yml "gopkg.in/yaml.v3"
"github.com/go-redis/redis/v8"
) )
// GetRedisServerInfo 获取 redis server info // GetRedisServerInfo 获取 redis server info
@@ -22,7 +23,7 @@ import (
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 12:24 下午 2021/11/27 // Date : 12:24 下午 2021/11/27
func GetRedisServerInfo(client *redisClient.ClusterClient) (*ServerInfo, error) { func GetRedisServerInfo(client *redis.Client) (*ServerInfo, error) {
var result ServerInfo var result ServerInfo
if err := infoToStruct(client, "server", &result); nil != err { if err := infoToStruct(client, "server", &result); nil != err {
return nil, err return nil, err
@@ -35,7 +36,7 @@ func GetRedisServerInfo(client *redisClient.ClusterClient) (*ServerInfo, error)
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 12:59 下午 2021/11/27 // Date : 12:59 下午 2021/11/27
func GetMemoryInfo(client *redisClient.ClusterClient) (*MemoryInfo, error) { func GetMemoryInfo(client *redis.Client) (*MemoryInfo, error) {
var result MemoryInfo var result MemoryInfo
if err := infoToStruct(client, "memory", &result); nil != err { if err := infoToStruct(client, "memory", &result); nil != err {
return nil, err return nil, err
@@ -48,7 +49,7 @@ func GetMemoryInfo(client *redisClient.ClusterClient) (*MemoryInfo, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:10 下午 2021/11/27 // Date : 1:10 下午 2021/11/27
func GetClientInfo(client *redisClient.ClusterClient) (*ClientInfo, error) { func GetClientInfo(client *redis.Client) (*ClientInfo, error) {
var result ClientInfo var result ClientInfo
if err := infoToStruct(client, "clients", &result); nil != err { if err := infoToStruct(client, "clients", &result); nil != err {
return nil, err return nil, err
@@ -61,7 +62,7 @@ func GetClientInfo(client *redisClient.ClusterClient) (*ClientInfo, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:11 下午 2021/11/27 // Date : 1:11 下午 2021/11/27
func GetPersistence(client *redisClient.ClusterClient) (*Persistence, error) { func GetPersistence(client *redis.Client) (*Persistence, error) {
var result Persistence var result Persistence
if err := infoToStruct(client, "persistence", &result); nil != err { if err := infoToStruct(client, "persistence", &result); nil != err {
return nil, err return nil, err
@@ -74,7 +75,7 @@ func GetPersistence(client *redisClient.ClusterClient) (*Persistence, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:19 下午 2021/11/27 // Date : 1:19 下午 2021/11/27
func GetStats(client *redisClient.ClusterClient) (*Stats, error) { func GetStats(client *redis.Client) (*Stats, error) {
var result Stats var result Stats
if err := infoToStruct(client, "stats", &result); nil != err { if err := infoToStruct(client, "stats", &result); nil != err {
return nil, err return nil, err
@@ -87,7 +88,7 @@ func GetStats(client *redisClient.ClusterClient) (*Stats, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:23 下午 2021/11/27 // Date : 1:23 下午 2021/11/27
func GetReplication(client *redisClient.ClusterClient) (*Replication, error) { func GetReplication(client *redis.Client) (*Replication, error) {
var result Replication var result Replication
if err := infoToStruct(client, "replication", &result); nil != err { if err := infoToStruct(client, "replication", &result); nil != err {
return nil, err return nil, err
@@ -101,7 +102,7 @@ func GetReplication(client *redisClient.ClusterClient) (*Replication, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 4:26 下午 2021/11/27 // Date : 4:26 下午 2021/11/27
func GetSlaveList(client *redisClient.ClusterClient) []SlaveNode { func GetSlaveList(client *redis.Client) []SlaveNode {
// 解析从库信息 // 解析从库信息
slaveList := make([]SlaveNode, 0) slaveList := make([]SlaveNode, 0)
var data map[string]string var data map[string]string
@@ -159,7 +160,7 @@ func GetSlaveList(client *redisClient.ClusterClient) []SlaveNode {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:24 下午 2021/11/27 // Date : 1:24 下午 2021/11/27
func GetCPUInfo(client *redisClient.ClusterClient) (*CPU, error) { func GetCPUInfo(client *redis.Client) (*CPU, error) {
var result CPU var result CPU
if err := infoToStruct(client, "cpu", &result); nil != err { if err := infoToStruct(client, "cpu", &result); nil != err {
return nil, err return nil, err
@@ -172,7 +173,7 @@ func GetCPUInfo(client *redisClient.ClusterClient) (*CPU, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:27 下午 2021/11/27 // Date : 1:27 下午 2021/11/27
func GetCommandStats(client *redisClient.ClusterClient) (*Stats, error) { func GetCommandStats(client *redis.Client) (*Stats, error) {
var result Stats var result Stats
if err := infoToStruct(client, "stats", &result); nil != err { if err := infoToStruct(client, "stats", &result); nil != err {
return nil, err return nil, err
@@ -185,7 +186,7 @@ func GetCommandStats(client *redisClient.ClusterClient) (*Stats, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 1:32 下午 2021/11/27 // Date : 1:32 下午 2021/11/27
func GetCommandInfo(client *redisClient.ClusterClient) ([]CmdStat, error) { func GetCommandInfo(client *redis.Client) ([]CmdStat, error) {
var result map[string]string var result map[string]string
if err := infoToStruct(client, "commandstats", &result); nil != err { if err := infoToStruct(client, "commandstats", &result); nil != err {
return make([]CmdStat, 0), err return make([]CmdStat, 0), err
@@ -236,7 +237,7 @@ func GetCommandInfo(client *redisClient.ClusterClient) ([]CmdStat, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 2:44 下午 2021/11/27 // Date : 2:44 下午 2021/11/27
func GetKeyspace(client *redisClient.ClusterClient) ([]DB, error) { func GetKeyspace(client *redis.Client) ([]DB, error) {
var result map[string]string var result map[string]string
if err := infoToStruct(client, "keyspace", &result); nil != err { if err := infoToStruct(client, "keyspace", &result); nil != err {
return make([]DB, 0), err return make([]DB, 0), err
@@ -277,7 +278,7 @@ func GetKeyspace(client *redisClient.ClusterClient) ([]DB, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 3:30 下午 2021/11/27 // Date : 3:30 下午 2021/11/27
func GetCluster(client *redisClient.ClusterClient) (*Cluster, error) { func GetCluster(client *redis.Client) (*Cluster, error) {
var result Cluster var result Cluster
if err := infoToStruct(client, "cluster", &result); nil != err { if err := infoToStruct(client, "cluster", &result); nil != err {
return nil, err return nil, err
@@ -290,7 +291,7 @@ func GetCluster(client *redisClient.ClusterClient) (*Cluster, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 3:35 下午 2021/11/27 // Date : 3:35 下午 2021/11/27
func GetErrorStats(client *redisClient.ClusterClient) ([]Error, error) { func GetErrorStats(client *redis.Client) ([]Error, error) {
var result map[string]string var result map[string]string
if err := infoToStruct(client, "errorstats", &result); nil != err { if err := infoToStruct(client, "errorstats", &result); nil != err {
return make([]Error, 0), err return make([]Error, 0), err
@@ -317,7 +318,7 @@ func GetErrorStats(client *redisClient.ClusterClient) ([]Error, error) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 12:28 下午 2021/11/27 // Date : 12:28 下午 2021/11/27
func infoToStruct(client *redisClient.ClusterClient, module string, receiver interface{}) error { func infoToStruct(client *redis.Client, module string, receiver interface{}) error {
data := client.Info(context.Background(), module).String() data := client.Info(context.Background(), module).String()
// yaml 文件规范要求, key: val , 注意 : 的后面有空格 // yaml 文件规范要求, key: val , 注意 : 的后面有空格
data = strings.ReplaceAll(data, ":", ": ") data = strings.ReplaceAll(data, ":", ": ")
+98
View File
@@ -0,0 +1,98 @@
// Package rate_limit ...
//
// Description : rate_limit ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-03-09 11:31
package rate_limit
import (
"context"
"time"
redisInstance "github.com/go-redis/redis/v8"
"github.com/go-redis/redis_rate/v9"
)
var (
// limiter 限流实例
limiter *redis_rate.Limiter
)
// InitLimiter 初始化限流器实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:40 2023/3/9
func InitLimiter(redisClient *redisInstance.Client) {
limiter = redis_rate.NewLimiter(redisClient)
}
// Second 每秒允许的访问数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:42 2023/3/9
func Second(ctx context.Context, key string, total, rate int) (bool, error) {
if total <= 0 || rate <= 0 {
return true, nil
}
res, err := limiter.AllowN(ctx, key, redis_rate.PerSecond(total), rate)
if nil != err {
return false, err
}
return res.Allowed > 0, nil
}
// Minute 每分钟允许访问数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:46 2023/3/9
func Minute(ctx context.Context, key string, total, rate int) (bool, error) {
if total <= 0 || rate <= 0 {
return true, nil
}
res, err := limiter.AllowN(ctx, key, redis_rate.PerMinute(total), rate)
if nil != err {
return false, err
}
return res.Allowed > 0, nil
}
// Hour 每小时允许访问数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:47 2023/3/9
func Hour(ctx context.Context, key string, total, rate int) (bool, error) {
if total <= 0 || rate <= 0 {
return true, nil
}
res, err := limiter.AllowN(ctx, key, redis_rate.PerHour(total), rate)
if nil != err {
return false, err
}
return res.Allowed > 0, nil
}
// Day 每天允许访问数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:47 2023/3/9
func Day(ctx context.Context, key string, total, rate int) (bool, error) {
if total <= 0 || rate <= 0 {
return true, nil
}
res, err := limiter.AllowN(ctx, key, redis_rate.Limit{
Rate: rate,
Period: 24 * time.Hour,
Burst: total,
}, rate)
if nil != err {
return false, err
}
return res.Allowed > 0, nil
}
+57 -76
View File
@@ -9,11 +9,9 @@ package redis
import ( import (
"context" "context"
"git.zhangdeman.cn/zhangdeman/redis/define"
"strings" "strings"
"time" "time"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/redis/define"
) )
var ( var (
@@ -21,124 +19,107 @@ var (
) )
// wrapper 常用命令的包装 // wrapper 常用命令的包装
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:16 2024/6/19
type wrapper struct { type wrapper struct {
} }
// Exist 缓存Key是否存在
func (w *wrapper) Exist(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandExists, key)
}
// TTL ...
func (w *wrapper) TTL(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandTTL, key)
}
// Get Get命令 // Get Get命令
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:17 2024/6/19
func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *define.RedisResult { func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandGet, key) return Client.Exec(ctx, instanceFlag, "GET", key)
} }
// Del 删除命令 // Del 删除命令
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:19 2024/6/19
func (w *wrapper) Del(ctx context.Context, instanceFlag string, keyList ...string) *define.RedisResult { func (w *wrapper) Del(ctx context.Context, instanceFlag string, keyList ...string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandDel, strings.Join(keyList, " ")) return Client.Exec(ctx, instanceFlag, "DEL", strings.Join(keyList, " "))
} }
// SetEx 设置数据并且带有效期, 有效期单位 : s // SetEx 设置数据并且带有效期, 有效期单位 : s
func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, value any, ttl int64, withLock bool) *define.RedisResult { //
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:22 2024/6/19
func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, value string, ttl int64, withLock bool) *define.RedisResult {
now := time.Now().Unix() now := time.Now().Unix()
if ttl > now { if ttl > now {
// 传入过期时间大于当前时间, 说明是指定具体时间过期, 做一下处理 // 传入过期时间大于当前时间, 说明是指定具体时间过期, 做一下处理
ttl = ttl - now ttl = ttl - now
} }
if withLock { if withLock {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandSet, key, value, "EX", ttl, "NX") return Client.Exec(ctx, instanceFlag, "SET", key, value, "EX", ttl, "NX")
} }
return Client.Exec(ctx, instanceFlag, consts.RedisCommandSet, key, value, "EX", ttl) return Client.Exec(ctx, instanceFlag, "SET", key, value, "EX", ttl)
} }
// LPop ... // LPop ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:29 2024/6/19
func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult { func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpop, key) return Client.Exec(ctx, instanceFlag, "LPOP", key)
} }
// RPop ... // RPop ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:30 2024/6/19
func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult { func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpop, key) return Client.Exec(ctx, instanceFlag, "RPOP", key)
} }
// LPush ... // LPush ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:31 2024/6/19
func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult { func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpush, key, value) return Client.Exec(ctx, instanceFlag, "LPUSH", key, value)
} }
// RPush ... // RPush ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:31 2024/6/19
func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult { func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpush, key, value) return Client.Exec(ctx, instanceFlag, "RPUSH", key, value)
} }
// HGet ... // HGet ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:33 2024/6/19
func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, field string) *define.RedisResult { func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, field string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHget, key, field) return Client.Exec(ctx, instanceFlag, "HGET", key, field)
} }
// HSet ... // HSet ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:33 2024/6/19
func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, field string, value string) *define.RedisResult { func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, field string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHset, key, field, value) return Client.Exec(ctx, instanceFlag, "HSET", key, field, value)
} }
// HDel ... // HDel ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:37 2024/6/19
func (w *wrapper) HDel(ctx context.Context, instanceFlag string, key string, fieldList ...string) *define.RedisResult { func (w *wrapper) HDel(ctx context.Context, instanceFlag string, key string, fieldList ...string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHdel, key, strings.Join(fieldList, " ")) return Client.Exec(ctx, instanceFlag, "HSET", key, strings.Join(fieldList, " "))
}
// BRPop ...
func (w *wrapper) BRPop(ctx context.Context, instanceFlag string, key []string, timeout int64) *define.RedisResult {
paramList := []any{}
for _, item := range key {
paramList = append(paramList, item)
}
paramList = append(paramList, timeout)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandBrpop, paramList...)
}
// BLPop ...
func (w *wrapper) BLPop(ctx context.Context, instanceFlag string, key []string, timeout int64) *define.RedisResult {
paramList := []any{}
for _, item := range key {
paramList = append(paramList, item)
}
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)
} }
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.