1. 程式人生 > >Jedis連線池

Jedis連線池


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>