Skip to content

Clustered Redis: periodic reconnects after idle; how to keep all channels active #3441

@patrykwierzbilo

Description

@patrykwierzbilo

I see reconnect INFO logs on idle against a managed, clustered Redis.
TCP keep-alive is enabled. No timeouts. Traffic is fine.
I need a supported pattern to keep all channels active when the app is idle.

Environment:

Lettuce:

  • lettuce-core:6.4.2.RELEASE
  • spring-cloud-azure-starter-data-redis-lettuce:5.22.0

Spring Boot: 3.4.8
spring-data-redis:3.4.8

Java: 21

Runtime: Kubernetes (Linux)/ AKS

Server: Azure Cache for Redis (TLS). Also reproduced locally with grokzen/redis-cluster (--timeout 45 --tcp-keepalive 0).

What happens

  • On idle, every ~10 min (or 45s in local repro) I see:
INFO ConnectionWatchdog: Reconnecting, last destination was <cache-host>:15000
INFO ReconnectionHandler: Reconnected to <cache-host>:15002
  • CLIENT LIST shows our client idle grows to the server timeout before the reconnect.

What I tried

  • Enabled TCP keep-alive (TCP keep-alive helps detect dead links but does not reset Redis’ idle counter).

  • No pool (single shared connection) + scheduled PING per shard like (tested locally)

  private final RedisConnectionFactory factory;

  @Scheduled(fixedRate = 20_000)
  public void pingAllShards() {

    try (RedisConnection raw = factory.getConnection()) {

      if (!(raw instanceof RedisClusterConnection cluster)) {
        log.warn("Heartbeat skipped – not a cluster connection");
        return;
      }

      for (RedisClusterNode node : cluster.clusterGetNodes()) {
        try {
          String pong = cluster.ping(node);
          log.debug("Heartbeat {}:{} → {}", node.getHost(), node.getPort(), pong);
        } catch (Exception ex) {
          log.warn("Heartbeat failed for {}", node, ex);
        }
      }
    }
  }

I used Lettuce config from documentation: link.

Why I’m asking

  • Operationally this is not breaking service, but the reconnect logs add noise.

  • I’d like a supported solution (pattern or API) that works with Spring Data and Lettuce, keeps clustered channels warm during idle, and avoids reconnects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions