当前位置: 首页 > news >正文

Spring Boot 和 Jedis版本搭配的建议

推荐版本组合

Spring Boot 版本Jedis 版本说明
3.1.xJedis 4.4.x+Spring Boot 3.x 基于 Java 17,需使用 Jedis 4.x(支持 Java 11+)。
2.7.xJedis 3.9.xSpring Boot 2.7.x 兼容 Java 8-17,推荐 Jedis 3.9.x(稳定版)。
2.6.x 及以下Jedis 3.6.x-3.8.x旧版 Spring Boot(Java 8 为主),使用 Jedis 3.x 早期版本。

详细说明

  1. Spring Boot 3.x + Jedis 4.x

    • 兼容性:Spring Boot 3.x 要求 Java 17+,Jedis 4.x 是唯一支持 Java 17 的版本。
    • 依赖方式
      <!-- Maven -->
      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
      </dependency>
      <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>4.4.3</version> <!-- 或最新稳定版 -->
      </dependency>
      
    • 注意:Spring Boot 3.x 默认使用 Lettuce 作为 Redis 客户端,若要切换到 Jedis,需排除 Lettuce 并显式引入 Jedis:
      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><exclusions><exclusion><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId></exclusion></exclusions>
      </dependency>
      
  2. Spring Boot 2.7.x + Jedis 3.9.x

    • 兼容性:Spring Boot 2.7.x 兼容 Java 8-17,Jedis 3.9.x 支持 Java 8+ 且修复了诸多 bug。
    • 依赖方式
      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
      </dependency>
      <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.9.1</version> <!-- 或最新稳定版 -->
      </dependency>
      
  3. 旧版 Spring Boot(2.6.x 及以下)+ Jedis 3.6.x-3.8.x

    • 兼容性:Jedis 3.6.x-3.8.x 支持 Java 8,与旧版 Spring Boot 更稳定兼容。
    • 依赖方式
      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
      </dependency>
      <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.8.4</version> <!-- 或适合 Java 8 的版本 -->
      </dependency>
      

版本选择建议

  • 新项目:优先使用 Spring Boot 3.1.x + Jedis 4.4.x(Java 17+),获得最新特性和安全修复。
  • 迁移项目:若无法升级 Java,使用 Spring Boot 2.7.x + Jedis 3.9.x(Java 8-17 兼容)。
  • 遗留项目:若需严格兼容 Java 8,使用 Spring Boot 2.6.x + Jedis 3.6.x

其他注意事项

  1. 连接池配置

    • Jedis 4.x 使用 GenericObjectPoolConfig,而 Jedis 3.x 使用 JedisPoolConfig
    • 示例配置(Spring Boot 3.x + Jedis 4.x):
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.redis.connection.RedisConnectionFactory;
      import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
      import org.springframework.data.redis.core.RedisTemplate;
      import redis.clients.jedis.JedisPoolConfig;@Configuration
      public class RedisConfig {@Beanpublic JedisPoolConfig jedisPoolConfig() {JedisPoolConfig poolConfig = new JedisPoolConfig();poolConfig.setMaxTotal(100);poolConfig.setMaxIdle(20);poolConfig.setMinIdle(5);return poolConfig;}@Beanpublic RedisConnectionFactory redisConnectionFactory(JedisPoolConfig poolConfig) {JedisConnectionFactory factory = new JedisConnectionFactory();factory.setPoolConfig(poolConfig);return factory;}
      }
      
  2. 替代方案

    • 若 Jedis 兼容性有问题,可考虑使用 Lettuce(Spring Boot 3.x 默认客户端),性能更高且完全异步。
    • Lettuce 依赖:
      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
      </dependency>
      <!-- Lettuce 已默认包含,无需额外引入 -->
      

根据项目的 Java 版本和需求选择合适的组合,确保版本间兼容且能获得长期支持。

http://www.xdnf.cn/news/464473.html

相关文章:

  • 【言语】刷题5
  • win11平台下的docker-desktop中的volume位置问题
  • Newtonsoft.Json.JsonSerializationException
  • 安卓A15系统实现修改锁屏界面默认壁纸功能
  • 多个docker-compose-xx 停止并完全卸载 删除
  • C++:字符数组与字符串指针变量的大小
  • 鸿蒙OSUniApp制作多选框与单选框组件#三方框架 #Uniapp
  • 协作赋能-1-制造业生产流程重构
  • Midjourney 最佳创作思路与实战技巧深度解析【附提示词与学习资料包下载】
  • 一些问题杂记
  • NY244NY249美光闪存颗粒NY252NY256
  • unity terrain 在生成草,树,石头等地形障碍的时候,无法触发碰撞导致人物穿过模型
  • 全链路压测实战指南:从理论到高可用架构的终极验证
  • Transformer的理解
  • Elasticsearch 分片机制高频面试题(含参考答案)
  • 【备忘踩坑】Android单元测试中读取测试assets的方法
  • 一套基于 Bootstrap 和 .NET Blazor 的开源企业级组件库
  • C#中Action的用法
  • Milvus Docker 部署教程
  • 【FFmpeg+SDL】使用FFmpeg捕获屏幕,SDL显示
  • 套路化编程:C# winform ListView 自定义排序
  • 5款AI驱动的MySQL数据库管理工具:提升运维效率的智能之选
  • 数智化招标采购系统如何实现分散评标?
  • Git/GitLab日常使用的命令指南来了!
  • Python——文件、异常、模块与包
  • 深入理解浏览器中的 window、document 和 window.parent
  • HarmonyOs开发之———UIAbility进阶
  • NVIDIA Omniverse 现已支持中文!
  • 问题处理——在ROS2(humble)+Gazebo+rqt下,无法显示仿真无人机的相机图像
  • 【LLIE专题】基于码本先验与生成式归一化流的低光照图像增强新方法