{"record":{"id":"4e4b68f34344546b","repo":"Billionmail/BillionMail","slug":"redis-env-init-error-v","errorCode":null,"errorMessage":"redis env init error: %v","messagePattern":"redis env init error: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/internal/service/redis_initialization/redis_initialization.go","lineNumber":19,"sourceCode":"package redis_initialization\n\nimport (\n\t\"billionmail-core/internal/service/public\"\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/gogf/gf/v2/database/gredis\"\n\t\"github.com/gogf/gf/v2/frame/g\"\n\t\"strconv\"\n\t\"time\"\n)\n\n// InitRedis initialize redis configuration\nfunc InitRedis() (err error) {\n\t// get redis password from environment variable\n\tpasswd, err := public.DockerEnv(\"REDISPASS\")\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"redis env init error: %v\", err)\n\t}\n\n\tdb := 1\n\tdbEnv, err := public.DockerEnv(\"REDISDB\")\n\tif err == nil {\n\t\tif dbVal, parseErr := strconv.Atoi(dbEnv); parseErr == nil {\n\t\t\tdb = dbVal\n\t\t}\n\t}\n\n\taddress := \"127.0.0.1:26379\"\n\n\tif public.IsRunningInContainer() {\n\t\taddress = \"redis:6379\"\n\t}\n\n\t// Initialize Redis configuration\n\tgredis.SetConfig(&gredis.Config{","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/redis_initialization/redis_initialization.go#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"Local runs without sourcing .env; renamed env variable in custom deployments; systemd/docker run commands missing --env-file.","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)."],"exampleFix":"// before\ngo run main.go            # REDISPASS unset\n// after\nexport REDISPASS=mysecret\ngo run main.go","handlingStrategy":"validation","validationCode":"if os.Getenv(\"REDISPASS\") == \"\" {\n    log.Fatal(\"REDISPASS environment variable must be set before starting\")\n}\nif err := redis_initialization.InitRedis(); err != nil {\n    log.Fatalf(\"redis init failed: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := redis_initialization.InitRedis(); err != nil {\n    if strings.Contains(err.Error(), \"redis env init error\") {\n        log.Fatal(\"REDISPASS is missing; load .env or run under docker compose\")\n    }\n    return err\n}","preventionTips":["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."],"tags":["redis","environment","startup"],"backgroundTag":"missing-env-var","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}