升级 cmd 枚举值类型

This commit is contained in:
2024-11-25 17:35:50 +08:00
parent a85ebc0203
commit 258311256f
5 changed files with 40 additions and 27 deletions

View File

@ -62,7 +62,7 @@ func (o *OwnClient) isAllowCommand(command string) bool {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:05 2024/6/19
func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command string, args ...any) *define.RedisResult {
func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command consts.RedisCmd, args ...any) *define.RedisResult {
if nil == ctx {
ctx = context.Background()
}
@ -99,7 +99,7 @@ func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command strin
zap.Int64("start_time", res.StartTime),
zap.Int64("finish_time", res.FinishTime),
zap.Int64("used_time", res.UsedTime),
zap.String("command", res.Command),
zap.String("command", res.Command.String()),
zap.String("arg_list", strings.Join(res.ArgList, " ")),
zap.String("execute_result", res.Result),
zap.Error(res.Err),
@ -145,11 +145,11 @@ func (o *OwnClient) Exec(ctx context.Context, instanceFlag string, command strin
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:02 2024/6/19
func (o *OwnClient) SetCommandWhiteList(commandList []string) {
func (o *OwnClient) SetCommandWhiteList(commandList []consts.RedisCmd) {
o.lock.Lock()
defer o.lock.Unlock()
for _, itemCommand := range commandList {
o.whiteCommandTable[strings.ToLower(strings.TrimSpace(itemCommand))] = true
o.whiteCommandTable[strings.ToLower(strings.TrimSpace(itemCommand.String()))] = true
}
}
@ -209,8 +209,8 @@ func (o *OwnClient) SetLogger(loggerInstance *zap.Logger, extraLogFieldList []st
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:22 2024/10/8
func (o *OwnClient) isWriteCommand(command string) bool {
return wrapperOperate.ArrayType([]string{
func (o *OwnClient) isWriteCommand(command consts.RedisCmd) bool {
return wrapperOperate.ArrayType([]consts.RedisCmd{
consts.RedisCommandDel,
consts.RedisCommandSet,
consts.RedisCommandLpush,
@ -218,7 +218,7 @@ func (o *OwnClient) isWriteCommand(command string) bool {
consts.RedisCommandMSet,
consts.RedisCommandPublish,
consts.RedisCommandPsubScribe,
}).Has(strings.ToUpper(command)) >= 0
}).Has(consts.RedisCmd(strings.ToUpper(command.String()))) >= 0
}
// newClient 获取客户端连接