<!-- redis start --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.8.6.RELEASE</version> </dependency> <!-- redis end -->
<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true" /> <!-- redis集群开始 --> <!-- string redis template definition --> <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory" /> </bean> <!-- redis template definition --> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory" /> <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> <!-- Spring-redis链接池管理工厂 --> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <constructor-arg ref="redisClusterConfiguration" /> <constructor-arg ref="jedisPoolConfig" /> <!-- Redis数据库索引(默认为0) --> <property name="database" value="${spring.redis.database}"/> </bean> <!-- 集群配置 --> <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration"> <property name="clusterNodes"> <set> <ref bean="clusterRedisNodes1"/> <ref bean="clusterRedisNodes2"/> <ref bean="clusterRedisNodes3"/> <ref bean="clusterRedisNodes4"/> <ref bean="clusterRedisNodes5"/> <ref bean="clusterRedisNodes6"/> </set> </property> <property name="maxRedirects" value="${spring.redis.maxRedirects}" /> </bean> <!-- 集群节点 --> <bean id="clusterRedisNodes1" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes1.host}" /> <constructor-arg value="${spring.redis.cluster.nodes1.port}" type="int" /> </bean> <bean id="clusterRedisNodes2" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes2.host}" /> <constructor-arg value="${spring.redis.cluster.nodes2.port}" type="int" /> </bean> <bean id="clusterRedisNodes3" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes3.host}" /> <constructor-arg value="${spring.redis.cluster.nodes3.port}" type="int" /> </bean> <bean id="clusterRedisNodes4" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes4.host}" /> <constructor-arg value="${spring.redis.cluster.nodes4.port}" type="int" /> </bean> <bean id="clusterRedisNodes5" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes5.host}" /> <constructor-arg value="${spring.redis.cluster.nodes5.port}" type="int" /> </bean> <bean id="clusterRedisNodes6" class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg value="${spring.redis.cluster.nodes6.host}" /> <constructor-arg value="${spring.redis.cluster.nodes6.port}" type="int" /> </bean> <!-- 集群节点 --> <!-- redis集群结束 --> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="${spring.redis.pool.max-active}" /> <property name="maxIdle" value="${spring.redis.pool.max-idle}" /> <property name="minIdle" value="${spring.redis.pool.min-idle}" /> <property name="maxWaitMillis" value="${spring.redis.pool.max-wait}" /> <property name="testOnBorrow" value="true" /> </bean>
redis.propertiesnode
###redis集群推送任务信息缓存 spring.redis.cluster.nodes1.host=127.0.0.1 spring.redis.cluster.nodes1.port=6380 spring.redis.cluster.nodes2.host=127.0.0.1 spring.redis.cluster.nodes2.port=6381 spring.redis.cluster.nodes3.host=127.0.0.1 spring.redis.cluster.nodes3.port=6382 spring.redis.cluster.nodes4.host=127.0.0.1 spring.redis.cluster.nodes4.port=6390 spring.redis.cluster.nodes5.host=127.0.0.1 spring.redis.cluster.nodes5.port=6390 spring.redis.cluster.nodes6.host=127.0.0.1 spring.redis.cluster.nodes6.port=6390 ## Redis数据库索引(默认为0) spring.redis.database=0 ## 链接超时时间(毫秒) spring.redis.timeout=60000 ## 最大重试次数 spring.redis.maxRedirects=3 ## 链接池最大链接数(使用负值表示没有限制)若是是集群就是每一个ip的链接数 spring.redis.pool.max-active=300 ## 链接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1 ## 链接池中的最大空闲链接 spring.redis.pool.max-idle=100 ## 链接池中的最小空闲链接 spring.redis.pool.min-idle=20
@Autowired @Resource(name="stringRedisTemplate") private StringRedisTemplate stringRedisTemplate;