开发者社区> 问答> 正文

Jedis2.7.2和spring-data-redis配置问题-redis报错

"

redis3.0.1集群已经搭建好了,然后用spring-data-redis连接集群


同样的配置:

<bean id="jedisConnectionFactory"
		class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
		destroy-method="destroy">
		<property name="hostName" value="10.3.1.226" />
		<property name="port" value="6380" />
		<property name="timeout" value="15000" />
		<property name="database" value="0" />
		<property name="password" value="" />
		<property name="usePool" value="true" />
		<property name="poolConfig" ref="jedisPoolConfig" />
	</bean>

	<!-- redis template definition p表示对该bean里面的属性进行注入,格式为p:属性名=注入的对象 效果与在bean里面使用<property>标签一样 -->
	<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
		p:connection-factory-ref="jedisConnectionFactory">
		<!-- 序列化方式 建议key/hashKey采用StringRedisSerializer。 -->
		<property name="keySerializer">
			<bean
				class="org.springframework.data.redis.serializer.StringRedisSerializer" />
		</property>
		<property name="hashKeySerializer">
			<bean
				class="org.springframework.data.redis.serializer.StringRedisSerializer" />
		</property>
		<property name="valueSerializer">
			<bean
				class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
		</property>
		<property name="hashValueSerializer">
			<bean
				class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
		</property>

	</bean>
	<!-- 对string操作的封装 -->
	<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"
		p:connection-factory-ref="jedisConnectionFactory" />
	<!-- <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" 
		c:template-ref="redisTemplate"/> -->



用jedis2.7.2就不行

<!-- jedis -->
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>2.7.2</version>
		</dependency>



换了jedis2.3.1就可以了

<!-- jedis -->
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>2.3.1</version>
		</dependency>




好奇怪,是怎么回事,有人能回答吗?   是jedis新版在配置上有什么更改了吗?  刚刚开始学redis,望高手赐教

"

展开
收起
montos 2020-06-04 10:25:28 869 0
1 条回答
写回答
取消 提交回答
  • 新版jedis改了Conection里的一个方法类型,所以导致之前的版本获取不到连接了,想用新版的话就自己改源码重新打包,不想改就坐等spring发布吧######这样,谢谢哈!######redis3.0.1集群 也要这么连接么?还需要配置ip和端口号?要是配置的端口的主服务挂掉了怎么办?######spring-data-redis目前支持不了redis3.0.1集群

    2020-06-04 10:33:39
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
ApsaraDB for Redis——与创客同行 立即下载
微博的Redis定制之路 立即下载
云数据库Redis版的开源之路 立即下载