springboot使用redisTemplate遇到的问题
概述
最近工作中新构建了一个项目,用的springboot,由于项目中要使用各种各样的缓存,就使用了spring-data-redis,这个东西比我想象中要难使用的多啊,而且我还遇到个问题,就是在用Redis来计数的时候,使用redisTemplate.opsForValue().increment()后,如果你再去get这值的时候就会报错,今天我们就来研究下,具体是为什么?
解决办法
public long getIncrValue(final String key) {
return redisTemplate.execute(new RedisCallback<Long>() {
@Override
public Long doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisSerializer serializer=(StringRedisSerializer) redisTemplate.getKeySerializer();
byte[] rowkey=serializer.serialize(key);
byte[] rowval=connection.get(rowkey);
try {
String val=serializer.deserialize(rowval);
return Long.parseLong(val);
} catch (Exception e) {
return 0L;
}
}
});
}
springboot使用redisTemplate遇到的问题的更多相关文章
- Springboot中RedisTemplate的操作
Springboot中RedisTemplate的操作 @Autowired private RedisTemplate redisTemplate; @Autowired private Strin ...
- springboot中RedisTemplate的使用
springboot中RedisTemplate的使用 参考 了解 Redis 并在 Spring Boot 项目中使用 Redis--以IBM为学习模板 springboot之使用redistemp ...
- SpringBoot 使用RedisTemplate操作Redis
新版: import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.T ...
- SpringBoot中RedisTemplate订阅发布对象
解说 RedisMessageListenerContainer Redis订阅发布的监听容器,你的消息发布.订阅配置都必须在这里面实现 addMessageListener(MessageListe ...
- springBoot 自定义redisTemplate
package com.atirm.mybatismutiplesource.config.RedisConfig; import com.atirm.mybatismutiplesource.ent ...
- SpringBoot使用RedisTemplate操作Redis时,key值出现 \xac\xed\x00\x05t\x00\tb
原因分析 原因与RedisTemplate源码中的默认序列化方式有关 defaultSerializer = new JdkSerializationRedisSerializer( classLoa ...
- Springboot中redisTemplate乱码或json转换问题
问题1 用RedisTemplate存入map值的时候,用rdm可视化打开,看到的是转码之后的数据,如图: 存入的方法为: public boolean hmset(String key, Map&l ...
- SpringBoot通过RedisTemplate执行Lua脚本
如果你对Redis和Lua的关系不太清楚,请先阅读:Redis进阶之使用Lua脚本开发 1.RedisScript 首先你得引入spring-boot-starter-data-redis依赖,其次把 ...
- 33. Springboot 系列 原生方式引入Redis,非RedisTemplate
0.pom.xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis&l ...
随机推荐
- asp.net简繁体转换
简繁体转换添加Microsoft.VisualBasic.dll引用 //简转繁 string str= Microsoft.VisualBasic.Strings.StrConv("民生银 ...
- 关于php下的ajax赋值传值的调试
在tp中, 在js中也可以使用 模板变量替换(比如__PUBLIC__)和 模板函数调用(比如: {:U('..')}) 等. 但是 只有直接放在 相应的 模板文件中, 只有放在index.html之 ...
- Linux下SSH远程连接断开后让程序继续运行解决办法
一.screen安装 yum install screen #CentOS安装 sudo apt-get install screen #ubuntu安装 二.screen常用命令 screen ...
- jenkin服务关闭和重启
1.关闭Jenkins http://localhost:8080/exit 2.重启Jenkies http://localhost:8080/restart 3.重新加载配置信息 http://l ...
- 环境准备—之—linux下安装python3和pip3
转自 上海悠悠 https://www.cnblogs.com/yoyoketang/p/10195102.html 前言 centos7 自带有 python,但是却是 python2 版本的 py ...
- JAVA-重载(overload)和重写(overrite)
1.重载发生在同一个类中.有多个方法名相同,但是参数列表不同(包括参数个数和参数类型),和返回值无关,权限修饰符也无关. 2.重写(即覆盖)发生在子类和父类中.子类和父类的方法名.参数列表相同:子类的 ...
- hive参数配置详细
hive.exec.mode.local.auto 决定 Hive 是否应该自动地根据输入文件大小,在本地运行(在GateWay运行) true hive.exec.mode.local.auto.i ...
- Hadoop InputFormat 输入文件分片
1. Mapper 与 Reducer 数量 对于一个默认的MapReduce Job 来说,map任务的数量等于输入文件被划分成的分块数,这个取决于输入文件的大小以及文件块的大小(如果此文件在 HD ...
- C#流程控制语句--跳转语句(break,continue,goto,return,)
跳转语句:是程序运行到某一位置时,可以跳到程序中另一个代码的语句.循环控制语句. 跳转语句:break 1.用于退出包含在最内层的循环或者退出一个switch或loop语句,程序流将继续紧接着loop ...
- angular 引入编辑器以及控制器的学习和理解。。。
在angular中引入编辑器的时候花了很长时间,然后发现自己以前根本就没好好用过angular,因为项目是接手的学姐的,学姐又是接手的学姐的,到我这里就只是写写页面的事了. 引入编辑器差了好多好多资料 ...