feat: 网元主机添加redis连接终端控制

This commit is contained in:
TsMask
2024-11-07 18:03:59 +08:00
parent 2c139e71c4
commit 9ac5ae50ec
8 changed files with 206 additions and 3 deletions

View File

@@ -59,3 +59,21 @@ func (c *ConnRedis) Close() {
c.Client.Close()
}
}
// RunCMD 执行单次命令 "GET key"
func (c *ConnRedis) RunCMD(cmd string) (any, error) {
if c.Client == nil {
return "", fmt.Errorf("redis client not connected")
}
// 写入命令
cmdArr := strings.Fields(cmd)
if len(cmdArr) == 0 {
return "", fmt.Errorf("redis command is empty")
}
conn := *c.Client
args := make([]any, 0)
for _, v := range cmdArr {
args = append(args, v)
}
return conn.Do(context.Background(), args...).Result()
}