lettuce和jedis的比较 Lettuce相较于Jedis有哪些优缺点? - 知乎
1. 依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
2.配置文件
redis:
database: 0
host:
port: 6379
password:
lettuce:
pool:
max-active: 8
max-wait: 1
max-idle: 8
min-idle: 0
3. 配置类
@Configuration
public class RedisConfig {@Beanpublic RedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory) {RedisTemplate template = new RedisTemplate();RedisSerializer<String> redisSerializer = new StringRedisSerializer();template.setConnectionFactory(connectionFactory);// key序列化方式template.setKeySerializer(redisSerializer);// value序列化template.setValueSerializer(redisSerializer);// value hashmap序列化template.setHashValueSerializer(redisSerializer);return template;}@Beanpublic StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory connectionFactory) {StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();stringRedisTemplate.setConnectionFactory(connectionFactory);return stringRedisTemplate;}
}