thanos-io/thanos · error

creating redis client

Error message

creating redis client: %v

What it means

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.

Solutions

  1. Check the wrapped inner error in the message for the root cause (address format, dial failure).
  2. Verify redis.endpoint is reachable: run redis-cli -h <host> -p <port> PING from the same host.
  3. Fix DNS/hostname resolution or correct the endpoint value in the config.
  4. Ensure network policies/firewalls allow TCP to the redis port.

Example fix

// before
redis:
  endpoint: redsi:6379
// after
redis:
  endpoint: redis:6379
Defensive patterns

Strategy: try-catch

Validate before calling

addr := net.JoinHostPort(host, port)
if _, err := net.ResolveTCPAddr("tcp", addr); err != nil { return fmt.Errorf("invalid redis endpoint %q: %w", addr, err) }

Try / catch

client, err := cache.New(cfg, ...)
if err != nil {
    if strings.Contains(err.Error(), "creating redis client") {
        log.Fatalf("redis cache unreachable, check endpoint: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling New() with cfg.Redis.Endpoint set and NewRedisClient failing — e.g. unparseable address, unreachable endpoint, or connection/Ping failure during client construction.

Common situations: Typo in redis endpoint host/port; Redis not running in the dev cluster; DNS name unresolvable at startup; network policy blocking the redis port.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/f08a1379f877c8fd. Report an issue: GitHub.

Appendix: source

Thrown at internal/cortex/chunk/cache/cache.go:108

		if cfg.Memcache.Expiration == 0 && cfg.DefaultValidity != 0 {
			cfg.Memcache.Expiration = cfg.DefaultValidity
		}

		client := NewMemcachedClient(cfg.MemcacheClient, cfg.Prefix, reg, logger)
		cache := NewMemcached(cfg.Memcache, client, cfg.Prefix, reg, logger)

		cacheName := cfg.Prefix + "memcache"
		caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg))
	}

	if cfg.Redis.Endpoint != "" {
		if cfg.Redis.Expiration == 0 && cfg.DefaultValidity != 0 {
			cfg.Redis.Expiration = cfg.DefaultValidity
		}
		cacheName := cfg.Prefix + "redis"
		redisClient, err := NewRedisClient(&cfg.Redis)
		if err != nil {
			return nil, errors.Errorf("creating redis client: %v", err)
		}
		cache := NewRedisCache(cacheName, redisClient, reg, logger)
		caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg))
	}

	cache := NewTiered(caches)
	if len(caches) > 1 {
		cache = Instrument(cfg.Prefix+"tiered", cache, reg)
	}
	return cache, nil
}

View on GitHub (pinned to 35b8b99117)