java操作redis,59集未完
spring data redis对jedis和lettuce进行了封装
Spring Data Rdis使用方式
配置类
@Configuration
@Slf4j
public class RedisConfiguration {
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
log.info("开始创建redis模板对象");
RedisTemplate redisTemplate = new RedisTemplate<>();
// 设置redis的连接工厂对象
redisTemplate.setConnectionFactory(redisConnectionFactory);
// 设置redis key的序列化器
redisTemplate.setKeySerializer(new StringRedisSerializer());
return redisTemplate;
}
}
#默认0号数据库
测试类
@SpringBootTest
public class SpringDataRedisTest {
@Autowired
private RedisTemplate redisTemplate;
@Test
public void testRedisTemplate(){
System.out.println(redisTemplate);
}
}
![](https://img2023.cnblogs.com/blog/2224132/202312/2224132-20231224205406294-1624529131.png)
本文来自博客园,作者:hellowworld!,转载请注明原文链接:https://www.cnblogs.com/zhangsai/p/17924824.html
posted on 2023-12-24 20:33 hellowworld! 阅读(2) 评论(0) 编辑 收藏 举报