JedisCluster接続redisクラスタ(パスワード付き)

16414 ワード

redisクラスタはredis-tribを介している.rb方式で構築する、接続する前にJedisパッケージ1を導入する必要がある.プロファイル
###############################redis        ##################################
##    
redis.auth = yangfuren
##    pool           Idle( ) jedis      8
redis.maxIdle = 200
##              8
redis.maxActive = 1024
##                     -1      ,             
redis.maxWait = 10000
redis.timeOut = 10000
##   true   borrow  jedis   ,   validate  
redis.testOnBorrow =true
##        (  )
redis.minEvictableIdleTimeMillis=1800000
##         (  )
redis.timeBetweenEvictionRunsMillis=30000
##           
redis.numTestsPerEvictionRun=1024
##     
redis.maxTotal=30
##         ,   false 
redis.testWhileIdle=true
##         , false   ,ture      ,   true
redis.blockWhenExhausted=false
redis.sockettimeout=1000
redis.maxAttempts=1000

#  
cluster.host1=ip
cluster.port1=6380
cluster.port2=6381
cluster.port3=6382
cluster.port4=6383
cluster.port5=6384
cluster.port6=6385

义齿xmlでの構成

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        
        <property name="maxTotal" value="${redis.maxTotal}"/>
        
        <property name="maxIdle" value="${redis.maxIdle}"/>
        
        <property  name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"/>
        
        <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"/>
        
        <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"/>
        
        <property name="softMinEvictableIdleTimeMillis" value="10000"/>
        
        <property name="maxWaitMillis" value="${redis.maxWait}"/>
        
        <property name="testOnBorrow" value="${redis.testOnBorrow}"/>
        
        <property name="testWhileIdle" value="${redis.testWhileIdle}"/>
        
        <property name="blockWhenExhausted" value="${redis.blockWhenExhausted}"/>
    bean>

    

    
     <bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">  
    <constructor-arg index="0">  
        <set>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port1}">constructor-arg>  
            bean>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port2}">constructor-arg>  
            bean>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port3}">constructor-arg>  
            bean>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port4}">constructor-arg>  
            bean>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port5}">constructor-arg>  
            bean>  
            <bean class="redis.clients.jedis.HostAndPort">  
                <constructor-arg index="0" value="${cluster.host1}">constructor-arg>  
                <constructor-arg index="1" value="${cluster.port6}">constructor-arg>  
            bean>  
        set>  
    constructor-arg>  
    <constructor-arg index="1" value="${redis.timeOut}">constructor-arg>  
    <constructor-arg index="2" value="${redis.sockettimeout}">constructor-arg>  
    <constructor-arg index="3" value="${redis.maxAttempts}">constructor-arg>  
    <constructor-arg index="4" value="${redis.auth}">constructor-arg>  
    <constructor-arg index="5" ref="jedisPoolConfig">constructor-arg>  
bean>  

呼び出し時に@Resource private SimpleRedisCluster simpleRedisCluster;注入後に呼び出せばいい