@@ -3,6 +3,7 @@ package sidekiq
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "strconv"
78 "strings"
89 "time"
@@ -59,24 +60,27 @@ type Client struct {
5960 redis * redis.Client
6061}
6162
62- // NewClient creates a new Sidekiq client with hardcoded Redis connection
63- func NewClient () * Client {
64- // Disable connection pool logging by setting MaxRetries to 0
65- // This prevents the pool from retrying and logging errors
66- rdb := redis .NewClient (& redis.Options {
67- Addr : "localhost:6379" ,
68- Password : "" ,
69- DB : 0 ,
70- MaxRetries : - 1 , // Disable retries completely
71- DialTimeout : 2 * time .Second , // Short timeout to fail fast
72- ReadTimeout : 2 * time .Second ,
73- WriteTimeout : 2 * time .Second ,
74- PoolSize : 1 , // Minimal pool size
75- })
76-
77- return & Client {
78- redis : rdb ,
63+ // NewClient creates a new Sidekiq client configured from a Redis URL.
64+ func NewClient (redisURL string ) (* Client , error ) {
65+ if redisURL == "" {
66+ redisURL = "redis://localhost:6379/0"
7967 }
68+
69+ opts , err := redis .ParseURL (redisURL )
70+ if err != nil {
71+ return nil , fmt .Errorf ("parse redis url: %w" , err )
72+ }
73+
74+ // Disable connection pool logging by disabling retries entirely.
75+ opts .MaxRetries = - 1 // Disable retries completely
76+ opts .DialTimeout = 2 * time .Second // Short timeout to fail fast
77+ opts .ReadTimeout = 2 * time .Second
78+ opts .WriteTimeout = 2 * time .Second
79+ opts .PoolSize = 1 // Minimal pool size
80+
81+ rdb := redis .NewClient (opts )
82+
83+ return & Client {redis : rdb }, nil
8084}
8185
8286// Close closes the Redis connection
0 commit comments