# os-core-cache **Repository Path**: os-core/os-core-cache ## Basic Information - **Project Name**: os-core-cache - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-18 - **Last Updated**: 2025-01-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 概述 此 SDK 旨在为不同的 Redis 部署模式(单机、主从、哨兵、集群)提供高效的数据源初始化服务,结合 Lettuce 连接池技术和 Spring Boot 自动配置功能,以增强 Redis 操作的性能和监控能力。 ## 特性 - **Lettuce 数据源初始化** - 高效管理 Redis 连接 - 支持连接池配置 - 提供性能优化选项 - 读写分离支持,在主从和集群模式下优先从从节点读取数据 - 灵活的连接池配置,优化连接的使用和资源管理 - **Spring Boot 自动配置** - 简化 Redis 配置 - 自动化管理 Redis 连接和模板 - 易于集成和扩展 ## 快速开始 ### 1. 添加依赖 确保在您的项目 `pom.xml` 文件中包含以下依赖项: ```xml com.evision.os os-core-cache 1.0-SNAPSHOT ``` ### 2. 配置数据源 根据您的 Redis 部署模式,编辑 `application.properties` 文件,加入以下相应的数据源配置: #### 2.1 Redis 单机模式 ```properties # Redis 数据源配置 spring.redis.mode = standalone spring.redis.host = 127.0.0.1 spring.redis.port = 6379 spring.redis.password = your_password spring.redis.database = 0 # Lettuce 连接池配置 spring.redis.lettuce.pool.min-idle = 10 spring.redis.lettuce.pool.max-idle = 50 spring.redis.lettuce.pool.max-active = 600 spring.redis.lettuce.pool.max-wait = 10000ms ``` #### 2.2 Redis 主从模式 ```properties # Redis 数据源配置 spring.redis.mode = master-slave spring.redis.master.host = master_host spring.redis.master.port = 6379 # 从节点配置 spring.redis.slaves[0].host = slave1_host spring.redis.slaves[0].port = 6380 spring.redis.slaves[1].host = slave2_host spring.redis.slaves[1].port = 6381 spring.redis.slaves[2].host = slave3_host spring.redis.slaves[2].port = 6382 # Redis 连接密码 spring.redis.password = your_password spring.redis.database = 0 # Lettuce 连接池配置 spring.redis.lettuce.pool.min-idle = 10 spring.redis.lettuce.pool.max-idle = 50 spring.redis.lettuce.pool.max-active = 600 spring.redis.lettuce.pool.max-wait = 10000ms ``` #### 2.3 Redis 哨兵模式 ```properties # Redis 数据源配置 spring.redis.mode = sentinel spring.redis.sentinel.master = mymaster spring.redis.sentinel.nodes = 127.0.0.1:26379,127.0.0.1:26380 spring.redis.sentinel.password = sentinel_password spring.redis.password = your_password spring.redis.database = 0 # Lettuce 连接池配置 spring.redis.lettuce.pool.min-idle = 10 spring.redis.lettuce.pool.max-idle = 50 spring.redis.lettuce.pool.max-active = 600 spring.redis.lettuce.pool.max-wait = 10000ms ``` #### 2.4 Redis 集群模式 ```properties # Redis 数据源配置 spring.redis.mode = cluster spring.redis.cluster.nodes = 127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002 spring.redis.cluster.max-redirects = 5 spring.redis.password = your_password # Lettuce 连接池配置 spring.redis.lettuce.pool.min-idle = 10 spring.redis.lettuce.pool.max-idle = 50 spring.redis.lettuce.pool.max-active = 600 spring.redis.lettuce.pool.max-wait = 10000ms ``` ### 3. 运行应用程序 完成上述配置后,您可以运行 Spring Boot 应用程序。SDK 将自动初始化数据源并启用配置的连接池和 RedisTemplate 功能。根据配置的 Redis 模式,连接将自动管理,并且操作将根据相应模式进行优化。 通过此配置,您的应用程序将能够高效地与不同模式的 Redis 部署进行交互,充分利用 Lettuce 连接池提供的性能优化和连接管理功能。