fix(backend): don't crash if redis isn't set, use tx in CreateMember

This commit is contained in:
Sam 2022-11-24 13:41:36 +01:00
parent 3b64ba33f6
commit d58208f5ac
3 changed files with 23 additions and 2 deletions

View File

@ -41,7 +41,8 @@ func New() (*DB, error) {
return nil, errors.Wrap(err, "creating redis client")
}
} else {
log.Warn("$REDIS was empty! ANY FUNCTIONALITY using redis will CRASH the server")
log.Warn("$REDIS was empty! Any functionality using Redis (such as authentication) will not work")
redis = &dummyRedis{}
}
minioClient, err := minio.New(os.Getenv("MINIO_ENDPOINT"), &minio.Options{

View File

@ -94,7 +94,7 @@ func (db *DB) CreateMember(ctx context.Context, tx pgx.Tx, userID xid.ID, name s
return m, errors.Wrap(err, "building sql")
}
err = pgxscan.Get(ctx, db, &m, sql, args...)
err = pgxscan.Get(ctx, tx, &m, sql, args...)
if err != nil {
pge := &pgconn.PgError{}
if errors.As(err, &pge) {

20
backend/db/redis.go Normal file
View File

@ -0,0 +1,20 @@
package db
import (
"context"
"net"
"emperror.dev/errors"
"github.com/mediocregopher/radix/v4"
)
var _ radix.Client = (*dummyRedis)(nil)
type dummyRedis struct{}
func (*dummyRedis) Addr() net.Addr { return &net.IPAddr{} }
func (*dummyRedis) Close() error { return nil }
func (*dummyRedis) Do(context.Context, radix.Action) error {
return errors.Sentinel("this is a dummy client")
}