jedis,spring-redis-data 整合使用,版本问题异常以及解决。
2016-03-23 10:06
1076 查看
最近整合使用redis spring-redis 出现了一下问题
spring:3.2.4.RELEASE
jedis: jedis 2.4.2
spring-data-redis: 1.5.2.RELEASE
各种折腾换了N个版本之后,启动的时候报错主要有一下两种:
最后得到如下配置是OK的:
版本问题解决了,先贴各项配置代码:
spring:
注入:
使用:
存值成功之后,存的值为:
在 redis-cli中查看值结果如下:
发现没,多了一个前缀 \xac\xed\x00\x05t\x00\b
这个为序列化的问题:http://blog.csdn.net/yunhaibin/article/details/9001198
参考资料:
http://zhaobing315.iteye.com/blog/2082189 http://www.cnblogs.com/tankaixiong/p/3660075.html http://www.sxt.cn/u/2839/blog/4363 http://www.cnblogs.com/tankaixiong/p/3660075.html
spring:3.2.4.RELEASE
jedis: jedis 2.4.2
spring-data-redis: 1.5.2.RELEASE
各种折腾换了N个版本之后,启动的时候报错主要有一下两种:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.isUserLevelMethod(Ljava/lang/reflect/Method;)Z
java.lang.VerifyError: Bad type on operand stack Exception Details: Location: org/springframework/data/redis/connection/jedis/JedisConnectionFactory.afterPropertiesSet()V
最后得到如下配置是OK的:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.2</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-xxx</artifactId> <version>3.2.4.RELEASE</version> </dependency>
版本问题解决了,先贴各项配置代码:
spring:
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="32"></property> <property name="maxIdle" value="6"></property> <property name="testOnBorrow" value="true" /> </bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy"> <property name="poolConfig" ref="jedisPoolConfig"></property> <property name="hostName" value="123.56.72.172"></property> <property name="port" value="6379"></property> <property name="password" value="redis"></property> <property name="timeout" value="15000"></property> <property name="usePool" value="true"></property> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory"></property> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> </property> </bean>
注入:
@Autowired private RedisTemplate<String, String> redisTemplate;
使用:
String paramK = "spring-redis-key"; String paramV ="Hello,spring-redis-data!!!"; redisTemplate.opsForValue().set(paramK, paramV);
存值成功之后,存的值为:
this ok.
在 redis-cli中查看值结果如下:
get spring-redis-key "\xac\xed\x00\x05t\x00\bthis ok."
发现没,多了一个前缀 \xac\xed\x00\x05t\x00\b
这个为序列化的问题:http://blog.csdn.net/yunhaibin/article/details/9001198
参考资料:
http://zhaobing315.iteye.com/blog/2082189 http://www.cnblogs.com/tankaixiong/p/3660075.html http://www.sxt.cn/u/2839/blog/4363 http://www.cnblogs.com/tankaixiong/p/3660075.html
相关文章推荐
- Linux服务器安装Redis
- Redis学习笔记
- Redis开源代码读书笔记零(Ubuntu14.04 64位安装)
- PHP_Redis自定类
- Redis入门教程
- redis单机环境安装
- redis之整数集合的实现源码分析
- Python下redis的使用(整理)
- redis学习笔记5--列表类型
- Redis的Java客户端Jedis
- YII2redis存储hash数据(mb_strlen() expects parameter 1 to be string, array given)
- Redis3安装(linux系统)
- 操作Redis之Jedis对象的生成方式
- 用jedis获取redis连接(集群和非集群状态下)
- Linux下php安装Redis扩展
- Redis 学习 ---- 8.对象
- Redis 数据持久化(一)
- redis 的基本语法
- Linux下redis的安装
- day10-redis操作