SpringBoot-整合redis
在SpringBoot中一般使用RedisTemplate提供的方法来操作Redis。那么使用SpringBoot整合Redis
需要那些步骤呢。
JedisPoolConfig(这个是配置连接池)
RedisConnectionFactory(这个是配置连接信息,这里的RedisConnectionFactory是一个接口,
我们需要使用它的实现类,在SpringD Data Redis方案中提供了一下四种工厂模型)JredisConnectionFactory
JedisConnectionFactory
LettuceConnectionFactory
SrpConnectionFactory
RedisTemplate
所需依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
所需配置
spring:
redis:
host: 127.0.0.1
port: 6379
password: 123456
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 500
min-idle: 0
lettuce:
shutdown-timeout: 0
测试环境
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test_1{
@Autowired
private RedisTemplate<String,String>redisTemplate;
@Test
public void set(){
redisTemplate.opsForValue().set("myKey","myValue");
System.out.println(redisTemplate.opsForValue().get("myKey"));
}
}
这里想要保存对象还需设置序列化器!序列化器有很多,这里不再说明,请自行百度。
SpringBoot-整合redis
https://blog.cikaros.top/doc/c8132148.html