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

玉溪网站建设制作如何做公司的网站建设

玉溪网站建设制作,如何做公司的网站建设,重庆seo优化公司哪家好,科技术语有哪些前言 随着 Spring Boot 3.x 的发布,其对 Java 17 的支持和 模块化架构 的深化,Redis 配置与集成方式发生了显著变化。今天简单讲下redis的变化 一、Redis 配置前缀的模块化演进:从 spring.redis 到 spring.data.redis 1.1 Spring Boot 2.x&…

前言

随着 Spring Boot 3.x 的发布,其对 Java 17 的支持和 模块化架构 的深化,Redis 配置与集成方式发生了显著变化。今天简单讲下redis的变化


一、Redis 配置前缀的模块化演进:从 spring.redisspring.data.redis

1.1 Spring Boot 2.x(Java 8)

  • 配置前缀spring.redis
  • 示例
    spring:redis:host: localhostport: 6379password: mypasswordtimeout: 2000lettuce:pool:max-active: 8max-idle: 8
    
  • 特点:直接通过 spring.redis 配置 Redis 连接参数,未明确与 Spring Data 模块绑定。

1.2 Spring Boot 3.x(Java 17)

  • 配置前缀spring.data.redis
  • 示例
    spring:data:redis:host: localhostport: 6379password: mypasswordtimeout: 2000msclient:type: lettucelettuce:pool:max-active: 8
    
  • 模块化设计:遵循 Spring Data Commons 的统一命名规则,与 spring.data.mongodb 等其他数据源保持一致,便于扩展和维护。

二、Redis 客户端库的颠覆性变化:Lettuce 一统天下

2.1 Spring Boot 2.x:Jedis 和 Lettuce 并存

  • 支持客户端
    • Jedis:基于阻塞式 I/O,适合简单场景。
    • Lettuce:基于 Netty 的非阻塞式,支持异步操作和响应式流(Reactive Streams)。
  • 配置示例
    spring:redis:client-type: jedis  # 或 lettucejedis:pool:max-active: 8lettuce:pool:max-active: 8
    

2.2 Spring Boot 3.x:Lettuce 独占

  • 官方声明
    • Jedis 客户端被弃用,仅支持 Lettuce。
    • 原因:Lettuce 的非阻塞特性更契合现代高并发场景,且与 Spring Reactor 生态深度集成。
  • 配置示例
    spring:data:redis:client-type: lettucelettuce:pool:max-active: 8max-wait: 1000ms
    
  • 迁移建议
    <!-- 移除 Jedis 相关依赖 -->
    <!-- 保留 Lettuce 依赖 -->
    <dependency><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId>
    </dependency>
    

三、RedisTemplate 的序列化策略升级:从 Java 序列化到 JSON

3.1 Spring Boot 2.x

  • 默认序列化器JdkSerializationRedisSerializer(基于 Java 序列化)。
  • 问题
    • 序列化后键值对难以直接读取(如 "\xac\xed\x00...")。
    • 跨语言兼容性差,且存在性能损耗。

3.2 Spring Boot 3.x

  • 默认序列化器GenericJackson2JsonRedisSerializer(基于 JSON)。
  • 优势
    • 键值对以 JSON 格式存储,可读性高。
    • 跨语言兼容性好,适合微服务场景。
  • 配置示例(若需恢复旧行为)
    @Configuration
    public class RedisConfig {@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new JdkSerializationRedisSerializer());template.setConnectionFactory(factory);return template;}
    }
    

四、集群与哨兵模式的配置迁移

4.1 Spring Boot 2.x

spring:redis:cluster:nodes: localhost:7000,localhost:7001sentinel:master: master1nodes: localhost:26379

4.2 Spring Boot 3.x

spring:data:redis:cluster:nodes: localhost:7000,localhost:7001sentinel:master: master1nodes: localhost:26379

五、连接池与超时参数的规范化

5.1 Spring Boot 2.x

spring:redis:lettuce:pool:max-active: 8max-idle: 8min-idle: 0max-wait: -1read-timeout: 1000

5.2 Spring Boot 3.x

spring:data:redis:lettuce:pool:max-active: 8max-idle: 8min-idle: 0max-wait: -1msread-timeout: 1000ms
  • 关键变化
    • 超时参数需显式指定单位(如 ms)。
    • max-wait 改为 max-wait-time(部分版本可能不同,需参考文档)。

六、Redisson 集成的路径调整

6.1 Spring Boot 2.x

spring:redis:redisson:config: |singleServerConfig:address: redis://localhost:6379

6.2 Spring Boot 3.x

spring:data:redis:redisson:config: |singleServerConfig:address: redis://localhost:6379

七、安全性配置:SSL/TLS 的统一路径

7.1 Spring Boot 3.x

spring:data:redis:ssl: truessl-trust-store: classpath:truststore.jksssl-trust-store-password: mypasswordssl-trust-store-type: JKS

八、迁移策略与最佳实践

8.1 配置文件迁移步骤

  1. 替换前缀
    • spring.redis 改为 spring.data.redis
  2. 移除 Jedis 配置
    • 删除 jedis.pool 相关参数。
  3. 检查超时单位
    • timeoutread-timeout 等参数添加 ms 后缀。

8.2 依赖管理

<!-- Spring Boot 3.x 依赖 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId><version>6.2.4.RELEASE</version> <!-- 保持最新版本 -->
</dependency>

8.3 测试与验证

@SpringBootTest
@AutoConfigureCache
public class RedisConfigTest {@Autowiredprivate RedisTemplate<String, String> redisTemplate;@Testpublic void testRedisConnection() {redisTemplate.opsForValue().set("testKey", "testValue");assertEquals("testValue", redisTemplate.opsForValue().get("testKey"));}
}

九、性能优化与高级配置

9.1 Lettuce 的异步与响应式支持

  • 异步操作
    @Autowired
    private ReactiveRedisTemplate<String, String> reactiveTemplate;public Mono<String> asyncGet(String key) {return reactiveTemplate.opsForValue().get(key);
    }
    
  • 响应式流集成
    @Autowired
    private Flux<String> reactiveKeys() {return reactiveTemplate.keys("pattern:*").flatMap(key -> reactiveTemplate.opsForValue().get(key));
    }
    

9.2 高级连接池配置

spring:data:redis:lettuce:pool:max-active: 100max-wait: 1000msmin-idle: 10max-idle: 50

十、总结:模块化设计的深层价值

Spring Boot 3.x 的配置调整并非简单的语法变化,而是 模块化设计 的体现:

  • 统一命名空间:通过 spring.data.redis 集中管理 Redis 配置,降低认知成本。
  • 技术演进:淘汰 Jedis,拥抱 Lettuce 的非阻塞特性,提升性能与可维护性。
  • 配置标准化:强制单位标注(如 timeout: 2000ms)减少配置歧义。

十一、附录:关键配置对比表

配置项Spring Boot 2.xSpring Boot 3.x
客户端类型spring.redis.client-typespring.data.redis.client-type
连接池配置spring.redis.poolspring.data.redis.lettuce.pool
JSON 序列化需手动配置默认启用
SSL 配置spring.redis.sslspring.data.redis.ssl
Redisson 集成路径spring.redis.redissonspring.data.redis.redisson

十二、进一步阅读

  • Spring Boot 3.x 迁移指南
  • Spring Data Redis 文档
  • Lettuce 官方文档

文章转载自:

http://m7xnwjT9.yLpwc.cn
http://fv0eKyPn.yLpwc.cn
http://wsBIGu3q.yLpwc.cn
http://K7qR0Miy.yLpwc.cn
http://oO74pnIu.yLpwc.cn
http://3zGFZnMk.yLpwc.cn
http://I6tw5FRh.yLpwc.cn
http://hO8752lA.yLpwc.cn
http://Py54I0yx.yLpwc.cn
http://QkYhC62Q.yLpwc.cn
http://6ibuiCsr.yLpwc.cn
http://WELlxcxT.yLpwc.cn
http://OohpDPHN.yLpwc.cn
http://6NLQotyd.yLpwc.cn
http://rpI7jGeH.yLpwc.cn
http://AVc2EMFe.yLpwc.cn
http://F8J2Xro0.yLpwc.cn
http://XZ3H0sEf.yLpwc.cn
http://NKBWv2BS.yLpwc.cn
http://5FhAVmsW.yLpwc.cn
http://YjdyqvDe.yLpwc.cn
http://I8kFCpXk.yLpwc.cn
http://7AlT4qbJ.yLpwc.cn
http://DGllhjGs.yLpwc.cn
http://30RjcRQc.yLpwc.cn
http://1nDdqFBX.yLpwc.cn
http://Ig1VMNWv.yLpwc.cn
http://eXKp1aZx.yLpwc.cn
http://k61gwCwn.yLpwc.cn
http://Oji6PKOr.yLpwc.cn
http://www.dtcms.com/wzjs/722204.html

相关文章:

  • 微动网站建设中国能源建设集团有限公司电子采购平台
  • 空包网站建设属于哪类WordPress评论加签到
  • 怎样做门户网站杭州免费建站
  • 做网站主要栏目内注册公司登陆哪个网站
  • 镇平网站建设wordpress编辑作者投稿者英文
  • 高端网站制作公网站提供的链接
  • 做网站多钱如何建立自己的平台
  • 做漫画在线观看网站python基础教程第二版答案
  • 优质东莞网站制作公司国家政务服务平台官网入口
  • 山东临沂网站开发如何做网站的页面
  • 公司两学一做网站免费空间网站源码
  • 购物建设网站费用网站模版 模板
  • 在哪个网站注册域名好去掉由WordPress提供
  • 网站做彩票犯法吗网站怎么申请微信支付
  • dw如何做网站登陆验证营销型网站建设页面
  • wordpress主题 外贸网站模板下载百度 seo 工具
  • 做html5视频网站来个网站吧好人一生平安2021
  • 手机网站分享最火的网页游戏
  • 茂名做网站公司c2c平台是指什么
  • 织梦网站后台默认登陆路径长春市供求世界在线看报
  • vue网站开发注意事项湖南seo优化服务
  • 做网站建设与推广企业网站设计 深圳
  • 网站查icp备案查询系统创客联盟网站建设
  • 图书类网站建设策划书wordpress基本设置
  • 织梦如何做视频网站做动画片的网站
  • 陕西网站关键词自然排名优化淘宝上做网站的信得过吗
  • 庐阳网站快速排名网站文章百度快照怎么做
  • 卖线面网站上海人才招聘信息最新招聘信息
  • 标准网站建设费用深圳互联网营销
  • 企业网站模板phpjoomla 网站建设教程