Redis连接池

📅 发布时间:2026/7/6 17:47:16 👁️ 浏览次数:
Redis连接池
Jedis连接池Jedis本身是线程不安全的并且频繁的创建和销毁连接会有性能损耗因此我们推荐大家使用jedis连接池代替jedis的直连方式SpringDataRedisSpringData是Spring中数据操作的模块包含对各种数据库的集成其中对Redis的集成模块就叫做SpringDataRedis提供了对不同Redis客户端的整合Lettuce和Jedis提供了RedisTemplate统一API来操作Redis支持Redis的发布订阅模型支持Redis哨兵和Redis集群支持基于Lettuce的响应式编程支持基于JDK、JSON、字符串、Spring对象的数据序列化及反序列化支持基于Redis的JDKCollection实现–基于Springboot引入这两个依赖–org.springframework.bootspring-boot-starter-data-redisorg.apache.commons commons-pool2 2.11.1spring:redis:host: 127.0.0.1port: 6379lettuce:pool:max-active: 8max-idle: 8min-idle: 0max-wait: 100msSpringBootTestclass RedisDemoApplicationTests {Autowiredprivate RedisTemplate redisTemplate;Testvoid contextLoads() {redisTemplate.opsForValue().set(“name”,“谷歌”);Object name redisTemplate.opsForValue().get(“name”);System.out.println(“name”name);}}