Billionmail/BillionMail · critical
redis env init error: %v
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.
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)
Solutions
- Export REDISPASS in the environment before starting the service.
- Run via docker compose so REDISPASS comes from the compose/.env configuration.
- Use --env-file .env with docker run, or load dotenv in dev scripts.
- 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
- Keep REDISPASS in .env and load it in every launch path (compose, systemd, dev scripts).
- Add a config preflight that checks required env vars at boot.
- Document REDISPASS in .env.example and the deployment README.
- Use health checks so a service that failed Redis init is not marked ready.
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
- no default jwt secret found
- redis connection test failed after 10 attempts
- Logout failed: %w
- failed to get validate code: %w
- rar command not found, please install it first
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/4e4b68f34344546b.
Report an issue: GitHub.