flipped-aurora/gin-vue-admin · critical
redis `%s` no init
Error message
redis `%s` no init
What it means
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.
Source
Thrown at server/global/global.go:65
defer lock.RUnlock()
return GVA_DBList[dbname]
}
// MustGetGlobalDBByDBName 通过名称获取db 如果不存在则panic
func MustGetGlobalDBByDBName(dbname string) *gorm.DB {
lock.RLock()
defer lock.RUnlock()
db, ok := GVA_DBList[dbname]
if !ok || db == nil {
panic("db no init")
}
return db
}
func GetRedis(name string) redis.UniversalClient {
redis, ok := GVA_REDISList[name]
if !ok || redis == nil {
panic(fmt.Sprintf("redis `%s` no init", name))
}
return redis
}
View on GitHub (pinned to 3136500ef3)
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
Example fix
// before
rdb := global.GetRedis("cache") // no such entry
// after (config.yaml)
redis:
- name: cache
addr: 127.0.0.1:6379
db: 0 Defensive patterns
Strategy: type-guard
Validate before calling
func redisReady(name string) bool { _, ok := global.GVA_REDISList[name]; return ok } // check before GetRedis Type guard
func safeRedis(name string) redis.UniversalClient { if r, ok := global.GVA_REDISList[name]; ok && r != nil { return r }; return nil } Try / catch
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 } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- fatal error config file: %w
- fatal error unmarshal config: %w
- db not init
- panic(err) — standalone MCP config load failed
- db no init
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/911c8b4dd1aae2ba.
Report an issue: GitHub.