Skip to content

Commit

Permalink
redisCache: Create funtion DoCommand method to execute any Redis command
Browse files Browse the repository at this point in the history
  • Loading branch information
yderana authored and agungdwiprasetyo committed Dec 5, 2024
1 parent 7c0f5a7 commit 796a788
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,22 @@ func (r *RedisCache) Delete(ctx context.Context, key string) (err error) {
}
return nil
}

// DoCommand method to execute any Redis command
func (r *RedisCache) DoCommand(ctx context.Context, isWrite bool, command string, args ...any) (reply any, err error) {
trace, ctx := tracer.StartTraceWithContext(ctx, "redis:do_command")
defer func() { trace.Finish(tracer.FinishWithError(err)) }()

trace.SetTag("db.command", command)
trace.Log("args", args)

// Select the appropriate connection pool (read or write)
cl := r.read.Get()
if isWrite {
cl = r.write.Get()
}
defer cl.Close()

// Execute the Redis command
return cl.Do(command, args...)
}

0 comments on commit 796a788

Please sign in to comment.