如何使用jedis集群设置Jedispool配置参数?

时间:2017-11-10 07:22:57

标签: redis jedis

我正在使用Ubuntu 16.04版本redis版本3.2.5我已经在redis中完成了一个集群,但我的问题是每当我在jedispool参数中设置池配置时它不会对此产生影响假设我将setMinIdle参数设置为2但它不能起作用意味着最小两个连接保持打开但在完成程序连接执行后为零(0)。                      还在这里当JedisCluster对象创建时,五个连接自动完成我无法理解为什么只有五个连接总是建立?以下是我的代码片段

public static void main(String[] args) throws InterruptedException {     
int maxConnection = 100;                                             
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();     
jedisClusterNodes.add(new HostAndPort("192.168.0.36", 7000));        
jedisClusterNodes.add(new HostAndPort("192.168.0.36", 7001));        

Jedis j = null;                                                      

JedisPoolConfig poolConfig = new JedisPoolConfig();                  
poolConfig.setMaxTotal(100);                                         
poolConfig.setMinIdle(2);                                            
JedisCluster jc = new JedisCluster(jedisClusterNodes, poolConfig);   

long start = System.currentTimeMillis();                             

for (int i = 0; i < maxConnection; i++) {                            
    RunIt rt = new RunIt(jedisClusterNodes, jc);                     
    Thread t = new Thread(rt);                                       
    t.setName("t" + i);                                              
    t.start();                                                       
}                                                                    
long end = System.currentTimeMillis();                               
long diff = end - start;                                             
double secs = (double) (diff / 1000);                                
Thread.currentThread().sleep(60000);                                 
System.out.println("Main Program executed");    

下面是我的其他课程

public class RunIt implements Runnable{                                                                  

Set<HostAndPort> jedisClusterNodes = null;                                                           
JedisCluster jc = null;                                                                              
static int conCount=0;                                                                               
static long errCount =0;                                                                             
public RunIt() {                                                                                     
}                                                                                                    
public RunIt(Set<HostAndPort> jedisClusterNodes , JedisCluster jc){                                  
    this.jedisClusterNodes = jedisClusterNodes;                                                      
    this.jc= jc;                                                                                     
}                                                                                                    

@Override                                                                                            
public void run() {                                                                                  
    for(int i=0; i< 1; i++){                                                                         
        connectToRedis(jedisClusterNodes,jc);                                                        
    }                                                                                                
    conCount++;                                                                                      
}                                                                                                    

private static void connectToRedis(Set<HostAndPort> jedisClusterNodes, JedisCluster jc){             

    try{                                                                                             
    jc.get("86ba15059795607378751a61eec9c");                                                         
    jc.get("ac64150607619266806e8be5abaf0");                                                         
    }catch (Exception e) {                                                                           
        e.printStackTrace();                                                                         
        errCount++;                                                                                  
        System.out.println(conCount+"  --  "+Thread.currentThread().getName()+"  --  "+errCount);    
        return;                                                                                      
    }                                                                                                
    System.out.println("Thread name : "+Thread.currentThread().getName());                           
    //jd.close();                                                                                    

之后在我的情况下使用此命令连接redis:redis-cli -p 7000 -c

并使用命令检查连接列表:client list

0 个答案:

没有答案
相关问题