From b9101e260b3f3d805b907335760b553a44edb5e3 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 20 Nov 2022 03:44:20 +0100 Subject: [PATCH] feat(api): allow not having a redis connection for development --- backend/db/db.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/db/db.go b/backend/db/db.go index 9ea4159..664157c 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -6,6 +6,7 @@ import ( "fmt" "os" + "codeberg.org/u1f320/pronouns.cc/backend/log" "emperror.dev/errors" "github.com/Masterminds/squirrel" "github.com/jackc/pgx/v4/pgxpool" @@ -33,9 +34,14 @@ func New() (*DB, error) { return nil, errors.Wrap(err, "creating postgres client") } - redis, err := (&radix.PoolConfig{}).New(context.Background(), "tcp", os.Getenv("REDIS")) - if err != nil { - return nil, errors.Wrap(err, "creating redis client") + var redis radix.Client + if os.Getenv("REDIS") != "" { + redis, err = (&radix.PoolConfig{}).New(context.Background(), "tcp", os.Getenv("REDIS")) + if err != nil { + return nil, errors.Wrap(err, "creating redis client") + } + } else { + log.Warn("$REDIS was empty! ANY FUNCTIONALITY using redis will CRASH the server") } minioClient, err := minio.New(os.Getenv("MINIO_ENDPOINT"), &minio.Options{