make connections to the correct redis url envs

This commit is contained in:
Andre Medeiros 2022-11-05 16:28:27 -04:00
parent 11f5f4df51
commit 70f48c87da
4 changed files with 21 additions and 7 deletions

View file

@ -39,7 +39,7 @@ func APICmd(ctx context.Context) *cobra.Command {
}
defer db.Close()
redis, err := cmdutil.NewRedisClient(ctx, 16)
redis, err := cmdutil.NewRedisLocksClient(ctx, 16)
if err != nil {
return err
}

View file

@ -46,13 +46,19 @@ func SchedulerCmd(ctx context.Context) *cobra.Command {
}
defer db.Close()
redis, err := cmdutil.NewRedisClient(ctx, 16)
redis, err := cmdutil.NewRedisLocksClient(ctx, 16)
if err != nil {
return err
}
defer redis.Close()
queue, err := cmdutil.NewQueueClient(logger, redis, "worker")
qredis, err := cmdutil.NewRedisQueueClient(ctx, 16)
if err != nil {
return err
}
defer qredis.Close()
queue, err := cmdutil.NewQueueClient(logger, qredis, "worker")
if err != nil {
return err
}

View file

@ -60,13 +60,13 @@ func WorkerCmd(ctx context.Context) *cobra.Command {
}
defer db.Close()
redis, err := cmdutil.NewRedisClient(ctx, consumers)
redis, err := cmdutil.NewRedisLocksClient(ctx, consumers)
if err != nil {
return err
}
defer redis.Close()
qredis, err := cmdutil.NewRedisClient(ctx, poolSize)
qredis, err := cmdutil.NewRedisQueueClient(ctx, poolSize)
if err != nil {
return err
}

View file

@ -36,8 +36,16 @@ func NewStatsdClient(tags ...string) (*statsd.Client, error) {
return statsd.New(os.Getenv("STATSD_URL"), statsd.WithTags(tags))
}
func NewRedisClient(ctx context.Context, maxConns int) (*redis.Client, error) {
opt, err := redis.ParseURL(os.Getenv("REDIS_URL"))
func NewRedisLocksClient(ctx context.Context, maxConns int) (*redis.Client, error) {
return newRedisClient(ctx, "REDIS_LOCKS_URL", maxConns)
}
func NewRedisQueueClient(ctx context.Context, maxConns int) (*redis.Client, error) {
return newRedisClient(ctx, "REDIS_QUEUE_URL", maxConns)
}
func newRedisClient(ctx context.Context, env string, maxConns int) (*redis.Client, error) {
opt, err := redis.ParseURL(os.Getenv(env))
if err != nil {
return nil, err
}