版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mengdonghui123456/article/details/78428310
1.前言
公司使用阿里云的云数据库Redis,在Spirng的配置中,传统的Jedis配置已经不合适了,因为本地连接云Redis服务需要输入密码才行,这样只有JedisPool中才有输入验证密码的属性,于是采用了JedisPool的方式来连接单击的Redis云服务。
2.配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="50" />
<property name="maxIdle" value="5" />
<property name="maxWaitMillis" value="2000" />
<property name="testOnBorrow" value="false" />
</bean>
<bean id="jedis.shardInfo1" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="47.**.12.**" /> //链接地址
<constructor-arg index="1" value="6379" />
<constructor-arg index="2" value="2000" />
<constructor-arg index="3" value="r-m5e116baa923c274" />
<property name="password" value="r-m5e116baa923c274:Vf123456789"></property>
</bean>
<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
<constructor-arg index="0" ref="jedisPoolConfig" />
<constructor-arg index="1">
<list>
<ref bean="jedis.shardInfo1" />
</list>
</constructor-arg>
</bean>
</beans>