shardedJedisPool 怎么在Spring MVC中整合使用

longwentao1999 2016-12-10 04:50:10
使用的是Spring4.0,在Spring MVC中想整合Redis的集群,客户端使用的是切片模式(ShardedJedis),applicationContext.xml和redis.properties文件都准备好后,在Java代码中怎么使用集群?
redis.properties文件内容如下:
#Master
redis.master.host=127.0.0.1
redis.master.port=9001

#Slaver
redis.slaver.host=127.0.0.1
redis.slaver.port=9002

redis.pool.maxTotal=1024
redis.pool.maxIdle=200
redis.pool.maxWaitMillis=1000
redis.pool.testOnBorrow=true

redis.pool.timeBetweenEvictionRunsMillis=30000
redis.pool.minEvictableIdleTimeMillis=30000
redis.pool.softMinEvictableIdleTimeMillis=10000
redis.pool.numTestsPerEvictionRun=1024

#1000*60*60*1
redis.pool.expire=3600000
redis.pool.unlock=false

applicationContext.xml文件内容如下:
<!-- jdbc,redis配置 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/jdbc.properties</value>
<value>classpath:config/redis.properties</value>
</list>
</property>
</bean>

<!-- redis属性配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.pool.maxTotal}" />
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="numTestsPerEvictionRun" value="${redis.pool.numTestsPerEvictionRun}" />
<property name="timeBetweenEvictionRunsMillis" value="${redis.pool.timeBetweenEvictionRunsMillis}" />
<property name="minEvictableIdleTimeMillis" value="${redis.pool.minEvictableIdleTimeMillis}" />
<property name="softMinEvictableIdleTimeMillis" value="${redis.pool.softMinEvictableIdleTimeMillis}" />
<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
</bean>

<!-- redis集群配置 -->
<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
<constructor-arg index="0" ref="jedisPoolConfig"/>
<constructor-arg index="1">
<list>
<bean name="master" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="${redis.master.host}" />
<constructor-arg index="1" value="${redis.master.port}" type="int" />
<constructor-arg index="2" value="instance:01" />
</bean>
<bean name="slaver" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="${redis.slaver.host}" />
<constructor-arg index="1" value="${redis.slaver.port}" type="int" />
<constructor-arg index="2" value="instance:02" />
</bean>
</list>
</constructor-arg>
</bean>
...全文
777 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

25,980

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧