thanos-io/thanos · error

failed to create redis client

Error message

failed to create redis client

What it means

When the cache type is REDIS, the factory constructs a Redis client via cacheutil.NewRedisClient; failures are wrapped as 'failed to create redis client'. Like the memcached path, this validates configuration (address, auth, timeouts) before any actual connection pool is exercised heavily.

Solutions

  1. Verify the addresses field points at reachable Redis instances (host:port)
  2. Add correct username/password/tls settings if Redis requires authentication
  3. Check timeout and connection-pool fields parse as valid durations/ints
  4. Inspect the wrapped inner error for the precise invalid parameter
  5. Test connectivity with redis-cli -h <host> -p <port> from the Thanos pod

Example fix

// before
config:
  type: REDIS
  redis:
    addresses: "6379"            # missing host
timeout: soon                     # invalid duration
// after
config:
  type: REDIS
  redis:
    addresses: "redis.cache.svc:6379"
timeout: 500ms
Defensive patterns

Strategy: validation

Validate before calling

for _, a := range redisAddresses {
    if _, _, err := net.SplitHostPort(a); err != nil { return fmt.Errorf("bad redis address %q: %w", a, err) }
}
if _, err := time.ParseDuration(redisTimeout); err != nil { return fmt.Errorf("bad redis timeout: %w", err) }

Try / catch

cb, err := storecache.NewCachingBucketFromYaml(yamlContent, logger, reg, bucket, router)
if err != nil {
    if strings.Contains(err.Error(), "failed to create redis client") {
        return fmt.Errorf("redis client config invalid (address/auth/timeouts): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: CachingWithBackendConfig.Type == REDIS and NewRedisClient returns an error: invalid or missing Redis address, bad auth config (username/password fields), invalid DB index, malformed timeout values, or an unrecognized client config field.

Common situations: Wrong REDIS address or port, Redis requiring auth but no credentials supplied, TLS settings mismatches, or mixing memcached-style config keys into a Redis cache entry.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at pkg/store/cache/caching_bucket_factory.go:134

		}
		c = cache.NewMemcachedCache("caching-bucket", logger, memcached, reg)
	case string(InMemoryBucketCacheProvider):
		c, err = cache.NewInMemoryCache("caching-bucket", logger, reg, backendConfig)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to create inmemory cache")
		}
	case string(GroupcacheBucketCacheProvider):
		const basePath = "/_galaxycache/"

		c, err = cache.NewGroupcache(logger, reg, backendConfig, basePath, r, bucket, cfg)
		if err != nil {
			return nil, errors.Wrap(err, "failed to create groupcache")
		}

	case string(RedisBucketCacheProvider):
		redisCache, err := cacheutil.NewRedisClient(logger, "caching-bucket", backendConfig, reg)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to create redis client")
		}
		c = cache.NewRedisCache("caching-bucket", logger, redisCache, reg)
	default:
		return nil, errors.Errorf("unsupported cache type: %s", config.Type)
	}

	// Include interactions with cache in the traces.
	c = cache.NewTracingCache(c)
	cfg.SetCacheImplementation(c)

	cb, err := NewCachingBucket(bucket, cfg, logger, reg)
	if err != nil {
		return nil, err
	}

	return cb, nil
}

View on GitHub (pinned to 35b8b99117)