redis 集羣配置

spring 和redis的配置

參照 http://blog.csdn.net/u013132051/article/details/53765344 文章配置成功

記錄一下:

1、jar包的升級 

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

2、spring-core 版本 3.3release以上


3、詳細配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:int-redis="http://www.springframework.org/schema/integration/redis"
	xmlns:redis="http://www.springframework.org/schema/redis" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
		http://www.springframework.org/schema/integration/redis http://www.springframework.org/schema/integration/redis/spring-integration-redis-3.0.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	
	<!-- jedis pool config -->
	<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxTotal" value="10" />
		<property name="maxIdle" value="10" />
		<property name="maxWaitMillis" value="10" />
		<property name="testOnBorrow" value="false" />
	</bean>
	
	<!--1.72 以上支持集羣    集羣配置  -->
	<!-- redisCluster 配置 -->
	<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="10.0.4.8"></constructor-arg>
                    <constructor-arg name="port" value="7000"></constructor-arg>
                </bean>

                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="10.0.4.8"></constructor-arg>
                    <constructor-arg name="port" value="7001"></constructor-arg>
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="10.0.4.8"></constructor-arg>
                    <constructor-arg name="port" value="7002"></constructor-arg>
                </bean>
            </set>
        </property>
    </bean>
	
	<!-- ReDis連接工廠 -->
    <bean id="redis4CacheConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <constructor-arg name="clusterConfig" ref="redisClusterConfig" />
        <property name="timeout" value="1000" />
        <property name="poolConfig" ref="jedisPoolConfig" />
    </bean>
	
	<!-- 存儲序列化 -->
	<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
	<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
	
	<!-- redis template definition -->
	<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<!-- 		<property name="connectionFactory" ref="redisConnectionFactory" /> -->
		<property name="connectionFactory" ref="redis4CacheConnectionFactory" />
		<property name="keySerializer" ref="stringRedisSerializer"/>
		<property name="valueSerializer" ref="jdkSerializationRedisSerializer"/>
	</bean>
	
		<!-- turn on declarative caching -->
	<cache:annotation-driven />
	<!-- declare Redis Cache Manager -->
	<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" c:redis-operations-ref="redisTemplate">
		<property name="expires" ref="cacheExpires" />
	</bean>
	<!-- Sets the expire time (in seconds) for cache regions (by key). -->
	<util:map id="cacheExpires">
		<entry key="deliveryZone" value="86400" />
		<entry key="deliveryCenter" value="86400" />
		<entry key="deliveryMethod" value="86400" />
		<entry key="PaymentMode" value="3600" />
		<entry key="PaymentMethod" value="3600" />
		<entry key="SecurityResources" value="3600" />
		<entry key="user" value="3600" />
		<entry key="role" value="3600" />
		<entry key="menuTree" value="3600" />
		<entry key="menu" value="3600" />
	</util:map>
	
	
</beans>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章