Billionmail/BillionMail · critical

redis env init error

Error message

redis env init error: %v

What it means

InitRedis reads the REDISPASS environment variable to configure the Redis client. If public.DockerEnv returns an error for REDISPASS (variable unset), initialization aborts with 'redis env init error: <cause>'. Like the JWT secret, this dependency is expected to be provided by the Docker environment.

Solutions

  1. Export REDISPASS in the environment before starting the service.
  2. Run via docker compose so REDISPASS comes from the compose/.env configuration.
  3. Use --env-file .env with docker run, or load dotenv in dev scripts.
  4. Verify the variable name is exactly REDISPASS (case-sensitive).

Example fix

// before
go run main.go            # REDISPASS unset
// after
export REDISPASS=mysecret
go run main.go
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("REDISPASS") == "" {
    log.Fatal("REDISPASS environment variable must be set before starting")
}
if err := redis_initialization.InitRedis(); err != nil {
    log.Fatalf("redis init failed: %v", err)
}

Try / catch

if err := redis_initialization.InitRedis(); err != nil {
    if strings.Contains(err.Error(), "redis env init error") {
        log.Fatal("REDISPASS is missing; load .env or run under docker compose")
    }
    return err
}

Prevention

When it happens

Trigger: Starting the service without REDISPASS exported; running outside docker compose where env vars aren't injected; DockerEnv failing for any other reason reading that variable.

Common situations: Local runs without sourcing .env; renamed env variable in custom deployments; systemd/docker run commands missing --env-file.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/4e4b68f34344546b. Report an issue: GitHub.

Appendix: source

Thrown at core/internal/service/redis_initialization/redis_initialization.go:19

package redis_initialization

import (
	"billionmail-core/internal/service/public"
	"context"
	"fmt"
	"github.com/gogf/gf/v2/database/gredis"
	"github.com/gogf/gf/v2/frame/g"
	"strconv"
	"time"
)

// InitRedis initialize redis configuration
func InitRedis() (err error) {
	// get redis password from environment variable
	passwd, err := public.DockerEnv("REDISPASS")

	if err != nil {
		return fmt.Errorf("redis env init error: %v", err)
	}

	db := 1
	dbEnv, err := public.DockerEnv("REDISDB")
	if err == nil {
		if dbVal, parseErr := strconv.Atoi(dbEnv); parseErr == nil {
			db = dbVal
		}
	}

	address := "127.0.0.1:26379"

	if public.IsRunningInContainer() {
		address = "redis:6379"
	}

	// Initialize Redis configuration
	gredis.SetConfig(&gredis.Config{

View on GitHub (pinned to fc36c76c05)