{"record":{"id":"f08a1379f877c8fd","repo":"thanos-io/thanos","slug":"creating-redis-client-v","errorCode":null,"errorMessage":"creating redis client: %v","messagePattern":"creating redis client: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cortex/chunk/cache/cache.go","lineNumber":108,"sourceCode":"\t\tif cfg.Memcache.Expiration == 0 && cfg.DefaultValidity != 0 {\n\t\t\tcfg.Memcache.Expiration = cfg.DefaultValidity\n\t\t}\n\n\t\tclient := NewMemcachedClient(cfg.MemcacheClient, cfg.Prefix, reg, logger)\n\t\tcache := NewMemcached(cfg.Memcache, client, cfg.Prefix, reg, logger)\n\n\t\tcacheName := cfg.Prefix + \"memcache\"\n\t\tcaches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg))\n\t}\n\n\tif cfg.Redis.Endpoint != \"\" {\n\t\tif cfg.Redis.Expiration == 0 && cfg.DefaultValidity != 0 {\n\t\t\tcfg.Redis.Expiration = cfg.DefaultValidity\n\t\t}\n\t\tcacheName := cfg.Prefix + \"redis\"\n\t\tredisClient, err := NewRedisClient(&cfg.Redis)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"creating redis client: %v\", err)\n\t\t}\n\t\tcache := NewRedisCache(cacheName, redisClient, reg, logger)\n\t\tcaches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg))\n\t}\n\n\tcache := NewTiered(caches)\n\tif len(caches) > 1 {\n\t\tcache = Instrument(cfg.Prefix+\"tiered\", cache, reg)\n\t}\n\treturn cache, nil\n}\n","sourceCodeStart":90,"sourceCodeEnd":120,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/internal/cortex/chunk/cache/cache.go#L90-L120","documentation":"New() wraps any error returned by NewRedisClient when constructing the Redis cache backend. The underlying client creation failed (bad address, DNS resolution, dial failure during handshake/ping), and this wrapper adds context that it happened while creating the redis client.","triggerScenarios":"Calling New() with cfg.Redis.Endpoint set and NewRedisClient failing — e.g. unparseable address, unreachable endpoint, or connection/Ping failure during client construction.","commonSituations":"Typo in redis endpoint host/port; Redis not running in the dev cluster; DNS name unresolvable at startup; network policy blocking the redis port.","solutions":["Check the wrapped inner error in the message for the root cause (address format, dial failure).","Verify redis.endpoint is reachable: run redis-cli -h <host> -p <port> PING from the same host.","Fix DNS/hostname resolution or correct the endpoint value in the config.","Ensure network policies/firewalls allow TCP to the redis port."],"exampleFix":"// before\nredis:\n  endpoint: redsi:6379\n// after\nredis:\n  endpoint: redis:6379","handlingStrategy":"try-catch","validationCode":"addr := net.JoinHostPort(host, port)\nif _, err := net.ResolveTCPAddr(\"tcp\", addr); err != nil { return fmt.Errorf(\"invalid redis endpoint %q: %w\", addr, err) }","typeGuard":null,"tryCatchPattern":"client, err := cache.New(cfg, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"creating redis client\") {\n        log.Fatalf(\"redis cache unreachable, check endpoint: %v\", err)\n    }\n    return err\n}","preventionTips":["Health-check the redis endpoint as part of readiness probes.","Validate endpoint host:port format before startup.","Keep redis credentials/endpoints in one validated config source."],"tags":["redis","cache","connection"],"backgroundTag":"connection-refused","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}