Springmvc+redis jedis.jar连接方式,ShardedJedisPool分片连接池

需要的jar包:
redis-2.6.1.jar

redis.properties配置:
# Redis settings
redis.host=172.*.*.*
redis.port=6379
redis.pass=leavay

redis.maxIdle=300
redis.maxTotal=600
redis.maxWaitMillis=1000
redis.testOnBorrow=true

applicationContext.xml配置:
<context:property-placeholder location="classpath:redis.properties" />

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
         <property name="maxIdle" value="${redis.maxIdle}" />
        <property name="maxTotal" value="${redis.maxTotal}" />
        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />
        <property name="minIdle" value="1"/>
        <property name="testOnReturn" value="true"/>
        <property name="testWhileIdle" value="true"/>
    </bean>

     <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"  scope="singleton">
        <constructor-arg index="0" ref="jedisPoolConfig" />
        <constructor-arg index="1">
            <list>
                <bean class="redis.clients.jedis.JedisShardInfo">
                    <!-- <constructor-arg name="host" value="${redis.uri}" /> -->
                     <constructor-arg name="host"  value="${redis.host}" />
                    <constructor-arg name="port" value="${redis.port}" />
                    <property name="password" value="${redis.pass}"></property>
                    <!-- <constructor-arg name="timeout" value="${redis.timeout}" /> -->
                     <!-- <constructor-arg index="2" value="instance:01"/> -->
                </bean>
            </list>
        </constructor-arg>
    </bean>
spring连接redis另一种方式:http://blog.csdn.net/u014378181/article/details/79064574

阅读更多
个人分类: redis spring
上一篇Springmvc+redis spring-data-redis.jar连接方式
下一篇Springmvc+redis jedis.jar redis集群连接方式,JedisSentinelPool哨兵连接池
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭