Skip to content

feat(redis): add support for both standalone and cluster Redis modes#505

Open
mosesyu95 wants to merge 3 commits into
iflytek:mainfrom
mosesyu95:main
Open

feat(redis): add support for both standalone and cluster Redis modes#505
mosesyu95 wants to merge 3 commits into
iflytek:mainfrom
mosesyu95:main

Conversation

@mosesyu95

Copy link
Copy Markdown

📋 Summary

This PR adds comprehensive support for both standalone and cluster Redis deployment modes to SkillHub, enabling flexible Redis configuration while maintaining full backward compatibility.

✨ Changes

New Features

  • Dual-mode Redis support: Applications can now run with either a single Redis instance or a Redis Cluster
  • Configuration-driven mode selection: Switch between modes via SPRING_DATA_REDIS_MODE environment variable
  • Backward compatible: Default behavior remains unchanged (standalone mode)

Implementation Details

Core Configuration (RedisConfig.java)

  • Conditional bean creation based on spring.data.redis.mode property
  • Standalone mode: Uses RedisStandaloneConfiguration with host/port/database
  • Cluster mode: Uses RedisClusterConfiguration with multiple nodes and redirect support
  • Both modes share the same RedisTemplate configuration

Configuration Updates

Documentation

Testing & Validation

🔧 Usage

Standalone Mode (Default)

# No changes needed - works as before
make dev-all

# Or explicitly specify
export SPRING_DATA_REDIS_MODE=standalone
export SPRING_DATA_REDIS_HOST=localhost
export SPRING_DATA_REDIS_PORT=6379
make dev-all

Cluster Mode

export SPRING_DATA_REDIS_MODE=cluster
export SPRING_DATA_REDIS_CLUSTER_NODES=redis-node1:6379,redis-node2:6379,redis-node3:6379
export SPRING_DATA_REDIS_CLUSTER_MAX_REDIRECTS=3
make dev-all

📊 Environment Variables

Variable Description Default Required for Cluster
SPRING_DATA_REDIS_MODE Redis mode: standalone or cluster standalone No
SPRING_DATA_REDIS_HOST Redis host (standalone) localhost No
SPRING_DATA_REDIS_PORT Redis port (standalone) 6379 No
SPRING_DATA_REDIS_PASSWORD Redis password (empty) Optional
SPRING_DATA_REDIS_DATABASE Database number (standalone) 0 No
SPRING_DATA_REDIS_CLUSTER_NODES Cluster nodes (comma-separated) (empty) Yes
SPRING_DATA_REDIS_CLUSTER_MAX_REDIRECTS Max redirects for cluster 3 Optional

✅ Testing Checklist

  • Backend compiles without errors
  • Configuration classes follow Spring Boot conventions
  • Backward compatibility maintained (default standalone mode)
  • Both modes use Lettuce client consistently
  • All existing Redis-dependent features work in both modes:
    • Session storage (Spring Session)
    • Rate limiting (RedisSlidingWindowRateLimiter)
    • Idempotency (IdempotencyInterceptor)
    • Device authentication (DeviceAuthService)
    • Auth failure throttling (AuthFailureThrottleService)
  • Documentation includes usage examples
  • Configuration validation script provided

🔄 Migration Guide

For existing deployments:

  • No action required - continues to work with default standalone mode
  • All existing environment variables remain supported

For new cluster deployments:

  1. Set up Redis Cluster infrastructure
  2. Configure cluster nodes via SPRING_DATA_REDIS_CLUSTER_NODES
  3. Set SPRING_DATA_REDIS_MODE=cluster
  4. Restart application

📝 Notes

  • The implementation uses Spring Boot's auto-configuration with conditional beans
  • No breaking changes to existing APIs or configuration structure
  • Cluster mode requires proper Redis Cluster setup before use
  • For production cluster deployments, ensure proper network configuration and security groups

🔗 Related Issues

Closes #[issue-number] (if applicable)


Reviewers: Please verify that all Redis-dependent features continue to work correctly in both modes.

@CLAassistant

CLAassistant commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants