{"record":{"id":"911c8b4dd1aae2ba","repo":"flipped-aurora/gin-vue-admin","slug":"redis-s-no-init","errorCode":null,"errorMessage":"redis `%s` no init","messagePattern":"redis `(.+?)` no init","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/global/global.go","lineNumber":65,"sourceCode":"\tdefer lock.RUnlock()\n\treturn GVA_DBList[dbname]\n}\n\n// MustGetGlobalDBByDBName 通过名称获取db 如果不存在则panic\nfunc MustGetGlobalDBByDBName(dbname string) *gorm.DB {\n\tlock.RLock()\n\tdefer lock.RUnlock()\n\tdb, ok := GVA_DBList[dbname]\n\tif !ok || db == nil {\n\t\tpanic(\"db no init\")\n\t}\n\treturn db\n}\n\nfunc GetRedis(name string) redis.UniversalClient {\n\tredis, ok := GVA_REDISList[name]\n\tif !ok || redis == nil {\n\t\tpanic(fmt.Sprintf(\"redis `%s` no init\", name))\n\t}\n\treturn redis\n}\n","sourceCodeStart":47,"sourceCodeEnd":69,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/global/global.go#L47-L69","documentation":"GetRedis fetches a named redis.UniversalClient from GVA_REDISList and panics with `redis \\`name\\` no init` when the name is unregistered or nil. Like the DB registry, Redis clients must be registered during initialization; the panic makes missing Redis configuration fail fast at first use.","triggerScenarios":"Calling global.GetRedis(\"name\") when config has no redis entry with that name (config.redis list lacks it), initialization was skipped (Redis disabled or failed to connect), or the name string doesn't match the configured alias.","commonSituations":"Enabling a feature (cache, timed tasks, plugin) that requires Redis without configuring it; running tests without a Redis instance and without skipping; typo between the alias in config.yaml and GetRedis argument.","solutions":["Add/verify the redis entry with that exact name in config.yaml so initialize.RegisterRedis registers it","Confirm redis initialization succeeded at startup (check logs for connection errors)","Fix the alias string passed to GetRedis to match the configured name","In tests, use global/testutil Redis init or guard the call path so Redis-dependent code is skipped when absent"],"exampleFix":"// before\nrdb := global.GetRedis(\"cache\") // no such entry\n// after (config.yaml)\nredis:\n  - name: cache\n    addr: 127.0.0.1:6379\n    db: 0","handlingStrategy":"type-guard","validationCode":"func redisReady(name string) bool { _, ok := global.GVA_REDISList[name]; return ok } // check before GetRedis","typeGuard":"func safeRedis(name string) redis.UniversalClient { if r, ok := global.GVA_REDISList[name]; ok && r != nil { return r }; return nil }","tryCatchPattern":"func getRedisSafe(name string) (r redis.UniversalClient, err error) { defer func() { if rec := recover(); rec != nil { err = fmt.Errorf(\"redis %s unavailable: %v\", name, rec) } }(); return global.GetRedis(name), nil }","preventionTips":["Grep GetRedis usages and verify every alias exists in config.yaml redis entries","Guard features that need Redis behind a config flag so they no-op when Redis is absent","Add a startup health check that pings each configured Redis instance","In tests, initialize Redis via testutil.NewRedisOrSkip so missing Redis skips cleanly"],"tags":["redis","panic","initialization","config"],"backgroundTag":"redis-not-initialized","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}