Skip to content

Commit 61269c7

Browse files
yderana9iksans
authored andcommitted
redisCache: Create funtion DoCommand method to execute any Redis command
1 parent aba28e6 commit 61269c7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cache/cache.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,22 @@ func (r *RedisCache) Delete(ctx context.Context, key string) (err error) {
132132
}
133133
return nil
134134
}
135+
136+
// DoCommand method to execute any Redis command
137+
func (r *RedisCache) DoCommand(ctx context.Context, isWrite bool, command string, args ...any) (reply any, err error) {
138+
trace, ctx := tracer.StartTraceWithContext(ctx, "redis:do_command")
139+
defer func() { trace.Finish(tracer.FinishWithError(err)) }()
140+
141+
trace.SetTag("db.command", command)
142+
trace.Log("args", args)
143+
144+
// Select the appropriate connection pool (read or write)
145+
cl := r.read.Get()
146+
if isWrite {
147+
cl = r.write.Get()
148+
}
149+
defer cl.Close()
150+
151+
// Execute the Redis command
152+
return cl.Do(command, args...)
153+
}

0 commit comments

Comments
 (0)