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>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值