spring-data-redis spring-boot日常
来源:互联网 发布:巫师3低配置优化 编辑:程序博客网 时间:2024/06/14 20:02
springBoot 配置config
/**
* 设置缓存对象的序列化方式,不设置会报错
* 另外对于json序列化,对象要提供默认空构造器
* @param redisTemplate[u][/u]
* @return
*/
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
controller
控制器调用RedisTemplate
@Autowired
private RedisTemplate<String, String> redisTemplate;
/*
redisTemplate.opsForValue();//操作字符串
redisTemplate.opsForHash();//操作hash
redisTemplate.opsForList();//操作list
redisTemplate.opsForSet();//操作set
redisTemplate.opsForZSet();//操作有序set
*/
/**
* 设置缓存对象的序列化方式,不设置会报错
* 另外对于json序列化,对象要提供默认空构造器
* @param redisTemplate[u][/u]
* @return
*/
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
controller
控制器调用RedisTemplate
@Autowired
private RedisTemplate<String, String> redisTemplate;
/*
redisTemplate.opsForValue();//操作字符串
redisTemplate.opsForHash();//操作hash
redisTemplate.opsForList();//操作list
redisTemplate.opsForSet();//操作set
redisTemplate.opsForZSet();//操作有序set
*/
阅读全文
0 0
- spring-data-redis spring-boot日常
- spring-boot-starter-data-redis
- spring-boot-data-redis线程池配置
- redis:spring-data-redis
- Spring Boot集成Spring Data
- Spring Boot整合Spring Data
- spring-boot-data-jpa
- spring boot data redis的三种配置方式
- Spring Boot + Spring Session + Redis
- spring boot使用redis
- spring boot session redis
- spring boot使用redis
- spring-boot redis 配置
- Spring boot + redis 项目
- Spring Boot Redis 集成
- redis-10-spring-boot
- spring boot+redis
- [spring-boot] 使用redis
- 关于间址周期和执行周期的取操作数的疑问
- 基于文本,优于轻量,用于交换数据——json解析(下篇)
- Maven系列笔记(二)—— Maven的本地仓库、中央仓库与私服
- python爬取贴吧图片
- 28.ResponseEntity与ResponseBody注解的关系
- spring-data-redis spring-boot日常
- 软件设计原则:低耦合高内聚
- @Aspect
- 为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里面有效? 为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里
- 安卓的打包发布
- 【剑指offer】合并两个排序的链表
- Android Fragment 你应该知道的一切
- springcloud的config更新配置
- java中二维码的生成及解析(含有图片)