springboot Cacheable(redis),解决key乱码问题
- import org.springframework.context.annotation.Bean;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
- import org.springframework.data.redis.serializer.RedisSerializer;
- import org.springframework.data.redis.serializer.StringRedisSerializer;
- import org.springframework.stereotype.Component;
- import javax.annotation.Resource;
- /**
- * Created with IntelliJ IDEA.
- * Description:
- * User: mingyanliao
- * Date: 2018-11-20
- * Time: 下午7:52
- */
- @Component
- public class CacheConfig {
- //String json
- @Resource
- private RedisTemplate<String,String> jsonRedisTemplate;
- @Bean(name="redisWithSerial")
- public RedisTemplate<Object, Object> getRedisTemplate(RedisTemplate<Object, Object> redisTemplate) {
- RedisSerializer<String> stringSerializer = new StringRedisSerializer();
- //json序列化方式
- GenericJackson2JsonRedisSerializer jsonRedisSerializer =new GenericJackson2JsonRedisSerializer();
- redisTemplate.setKeySerializer(stringSerializer);
- redisTemplate.setValueSerializer(jsonRedisSerializer);
- redisTemplate.setHashKeySerializer(stringSerializer);
- redisTemplate.setHashValueSerializer(jsonRedisSerializer);
- return redisTemplate;
- }
- }
键值使用StringRedisSerializer,value使用GenericJackson2JsonRedisSerializer
- import com.baomidou.mybatisplus.core.mapper.BaseMapper;
- import org.apache.ibatis.annotations.Mapper;
- import org.apache.ibatis.annotations.Param;
- import org.apache.ibatis.annotations.Select;
- import org.springframework.cache.annotation.CacheConfig;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.Cacheable;
- /**
- * <p>
- * Mapper 接口
- * </p>
- *
- * @author myliao
- * @since 2018-11-20
- */
- @Mapper
- public interface MessageAutoanswerMapper extends BaseMapper<MessageAutoanswer> {
- @Cacheable(value = "panda_autoanswer",key="'m_'+#p0+'_'+#p1+'_'+#p2")
- @Select("select * from panda_wechat_message_autoanswer where wechat_id=#{wechatId} and subscribe_msg_type=#{msg_type} and msg_rule=#{rule}")
- public MessageAutoanswer getMessageAutoanswer(@Param("wechatId")Long wechatId, @Param("msg_type")String msg_type, @Param("rule")String rule);
- @CacheEvict(value = "panda_autoanswer",key="'m_'+#p0.wechatId+'_'+#p0.subscribeMsgType+'_'+#p0.msgRule")
- @Override
- public int insert(MessageAutoanswer messageAutoanswer);
- }
注意:Cacheable的value是指缓存名称,即redis里面的分组名称
springboot Cacheable(redis),解决key乱码问题的更多相关文章
- 【springBoot】springBoot集成redis的key,value序列化的相关问题
使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...
- SpringBoot集成redis的key,value序列化的相关问题
使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...
- SpringBoot2.X + SpringCache + redis解决乱码问题
环境:SpringBoot2.X + SpringCache + Redis Spring boot默认使用的是SimpleCacheConfiguration,使用ConcurrentMapCach ...
- SpringBoot整合Redis在可视化工具乱码问题,以及常用的api
pom依赖: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...
- SpringBoot整合redis实现过期key监听事件
Spring整合redis实现key过期事件监听:https://www.cnblogs.com/pxblog/p/13969375.html 可以用于简单的过期订单取消支付.7天自动收货场景中 1. ...
- 带着新人学springboot的应用04(springboot+mybatis+redis 完)
对于缓存也说了比较多了,大家对下图这一堆配置类现在应该有些很粗略的认识了(因为我也就很粗略的认识了一下,哈哈!),咳,那么我们怎么切换这个缓存呢?(就是不用springboot提供的默认的Simple ...
- SpringBoot整合Redis及Redis工具类撰写
SpringBoot整合Redis的博客很多,但是很多都不是我想要的结果.因为我只需要整合完成后,可以操作Redis就可以了,并不需要配合缓存相关的注解使用(如@Cacheable). ...
- 28. SpringBoot 集成Redis
1.引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- SpringBoot集成Redis分布式锁以及Redis缓存
https://blog.csdn.net/qq_26525215/article/details/79182687 集成Redis 首先在pom.xml中加入需要的redis依赖和缓存依赖 < ...
随机推荐
- Hyperledger Fabric 建立一个简单网络
Building you first network 网络结构: 2个Orgnizations(每个Org包含2个peer节点)+1个solo ordering service 打开fabric-sa ...
- iOS Build Apps for the World WWDC
Programming Resources https://developer.apple.com/internationalization/ WWDC Session Videos Internat ...
- python3 进行字符串、日期、时间、时间戳相关转换
1.字符串转换成时间戳 2. 日期转换成时间戳
- 设置eclipse联想功能
当我们在用eclipse的时候,怎么能够让自己的编码速度加快?我想利用eclipse的提示功能是其中的方法之一.下面就利出配置eclipse联想功能(代码的提示功能)的步骤: 1. 打开Eclipse ...
- 【原创】Arduino入门基础知识总结
一.概述 Arduino是源自意大利的一个开放源代码的硬件项目平台,该平台包括一块具备简单I/O功能的电路板以及一套程序开发环境软件. Arduino可以用来开发交互产品,比如它可以读取大量的开 ...
- c++单链表冒泡排序(交换结点),链表增删改查,运算符重载
#include <iostream> #include <stdlib.h> #include <time.h> #include <fstream> ...
- 【温故知新】HTTP请求GET和POST的用法和区别
转自http://www.w3school.com.cn GET的使用 请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的: /test/demo_form.asp?name1=v ...
- WPF-在Grid中编程添加控件
摘要: 在Grid中编程添加控件,布局控件的位置用到的代码是: gridLayout.Children.Add(textblock); Grid.SetRow(textblock, ); Grid.S ...
- 固态硬盘Ghost安装Windows 10无法引导的问题
机器配置如下: 电脑型号 技嘉 B360M POWER 台式电脑 操作系统 Windows 10 64位 ( DirectX 12 ) 处理器 英特尔 Core i7-8700 @ 3.20GHz 六 ...
- JSP中重定向页面没有全屏显示的问题解决
<script type="text/javascript"> window.onload=function(){ if(window.parent != window ...