Spring Data Redis application connection failure after Valkey cluster recovery
search cancel

Spring Data Redis application connection failure after Valkey cluster recovery

book

Article ID: 452009

calendar_today

Updated On:

Products

VMware Tanzu Spring Runtime

Issue/Introduction

An application using Spring Data Redis to connect to a Valkey cluster may experience connection failures after a primary node failure and replica promotion. The connection does not recover automatically, and functionality is only restored after restarting the application.

Symptoms:

  • Repository connection unable to perform operations after cluster recovery.
  • Cluster status transitions from "down" to "ok," but application connections remain stale.

Environment

Project: Spring Data Redis

Cause

Spring Data Redis cluster refresh is not explicitly enabled via the adaptive cluster state variable.

Resolution

  1. Configure the application to enable adaptive cluster refresh.

  2. Update the application.yml file to include the adaptive refresh settings:
    spring:
    data:
    redis:
    cluster:
    nodes:
    - valkey-node-1:6379
    - valkey-node-2:6379
    - valkey-node-3:6379
    lettuce:
    cluster:
    refresh:
    # Re-fetches the cluster state when errors occur
    adaptive: true
    # Periodically re-fetches cluster topology to ensure it stays up to date
    period: 30s

Additional Information

  • This solution presumes the use of the Lettuce driver.
  • Spring Data Redis Project