spring-data-redis整合redis集群配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30038111/article/details/84655155

Spring版本:4.3.21.RELEASE
spring-data-redis版本:

<dependency>
	<groupId>org.springframework.data</groupId>
	<artifactId>spring-data-redis</artifactId>
	<version>1.7.2.RELEASE</version>
</dependency>

jedis版本:

<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>2.9.0</version>
</dependency>

spring-redis.xml:

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.p7.demo.redis" />

<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
	<property name="minIdle" value="2" />
	<property name="maxIdle" value="10" />
	<property name="maxTotal" value="20" />
	<property name="maxWaitMillis" value="1000" />
	<property name="testOnBorrow" value="true" />
	<property name="minEvictableIdleTimeMillis" value="3000" />
</bean>
<bean id="redisClusterConfig"
	class="org.springframework.data.redis.connection.RedisClusterConfiguration">
	<property name="maxRedirects" value="3"></property>
	<property name="clusterNodes">
		<set>
			<bean class="org.springframework.data.redis.connection.RedisNode">
				<constructor-arg name="host" value="192.168.1.11"></constructor-arg>
				<constructor-arg name="port" value="6379"></constructor-arg>
			</bean>
			<bean class="org.springframework.data.redis.connection.RedisNode">
				<constructor-arg name="host" value="192.168.1.11"></constructor-arg>
				<constructor-arg name="port" value="6380"></constructor-arg>
			</bean>
			<bean class="org.springframework.data.redis.connection.RedisNode">
				<constructor-arg name="host" value="192.168.1.11"></constructor-arg>
				<constructor-arg name="port" value="6381"></constructor-arg>
			</bean>
		</set>
	</property>
</bean>

<!-- Redis 连接工厂 -->
<bean id="jeidsConnectionFactory"
	class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
	<constructor-arg name="clusterConfig" ref="redisClusterConfig" />
	<property name="poolConfig" ref="poolConfig" />
	<property name="usePool" value="true" />
	<property name="timeout" value="5000" />
</bean>

<!-- 
	Redis 客户端 
	@Resource
	private RedisTemplate redisTemplate;
-->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
	<property name="connectionFactory" ref="jeidsConnectionFactory" />
</bean>

<!-- 
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
	<property name="connectionFactory" ref="jeidsConnectionFactory" />
</bean>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
	<property name="connectionFactory" ref="jeidsConnectionFactory" />
	<property name="keySerializer">
		<bean
			class="org.springframework.data.redis.serializer.StringRedisSerializer" />
	</property>
	<property name="valueSerializer">
		<bean
			class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
	</property>
	<property name="hashKeySerializer">
		<bean
			class="org.springframework.data.redis.serializer.StringRedisSerializer" />
	</property>
	<property name="hashValueSerializer">
		<bean
			class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
	</property>
</bean>
 -->

猜你喜欢

转载自blog.csdn.net/qq_30038111/article/details/84655155