spring+redis 集群下的操作
<?xml version="1.0" encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean>
<property name="locations">
<list>
<value>classpath:/redis.properties</value>
</list>
</property>
</bean>
<!-- xml方式配置cluster-->
<bean> <constructor-arg value="${redis.host1}" />
<constructor-arg value="${redis.port1}" type="int" />
</bean>
<bean> <constructor-arg value="${redis.host2}" />
<constructor-arg value="${redis.port2}" type="int" />
</bean>
<bean> <constructor-arg value="${redis.host3}" />
<constructor-arg value="${redis.port3}" type="int" />
</bean>
<bean> <constructor-arg value="${redis.host4}" />
<constructor-arg value="${redis.port4}" type="int" />
</bean>
<bean> <constructor-arg value="${redis.host5}" />
<constructor-arg value="${redis.port5}" type="int" />
</bean>
<bean> <constructor-arg value="${redis.host6}" />
<constructor-arg value="${redis.port6}" type="int" />
</bean>
<bean >
<property name="maxRedirects" value="${spring.redis.cluster.max-redirects}" >
</property>
<property name="clusterNodes" >
<set>
<ref bean="clusterRedisNodes1" />
<ref bean="clusterRedisNodes2" />
<ref bean="clusterRedisNodes3" />
<ref bean="clusterRedisNodes4" />
<ref bean="clusterRedisNodes5" />
<ref bean="clusterRedisNodes6" />
</set>
</property>
</bean>
<bean> <property name="minIdle" value="${redis.minIdle}" />
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean >
<!-- 集群 -->
<bean
p:usePool="true">
<constructor-arg index="0" ref="redisClusterConfiguration" />
<constructor-arg index="1" ref="poolConfig"></constructor-arg>
</bean >
<!-- 单机 -->
<!--<bean-->
<!--class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"-->
<!--p:hostName="192.168.1.42" p:port="6379" p:password="gxdgroup" p:database="0"-->
<!--p:poolConfig-ref="poolConfig" p:usePool="true"/>-->
<!-- Spring Data Redis 设置 -->
<!-- redis 序列化策略 ,通常情况下key值采用String序列化策略, -->
<!-- 如果不指定序列化策略,StringRedisTemplate的key和value都将采用String序列化策略; -->
<bean/>
<!--<bean>-->
<!--<!–如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can't cast to String!!–>-->
<!--<property name="connectionFactory" ref="jedisConnectionFactory" />-->
<!--<property name="keySerializer" >-->
<!--<bean />-->
<!--</property>-->
<!--<property name="hashKeySerializer">-->
<!--<bean/>-->
<!--</property>-->
<!--</bean>-->
<bean>
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>
<!-- 自动扫描dao和service包(自动注入) -->
<context:component-scan base-package="com.xdth.redis.*" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
</context:component-scan>
</beans>
页:
[1]