1. 导包
org.springframework.boot
spring-boot-starter-data-redis
2.添加配置
redis:
host: 162.14.81.119
port: 6379
password: zy123456
connect-timeout: 10s
jedis:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1m
3.测试
@Autowired
private RedisTemplate redisTemplate;
@Test
void testRedis(){
redisTemplate.opsForValue().set("ntxz","568");
System.out.println(redisTemplate.opsForValue().get("ntxz"));
}
4.Redis默认使用二进制序列化,更改序列化方式为JSON(对象要实现序列化接口)
@Configuration
public class RedisConfig{
@Bean
public RedisTemplate