3

I'm using Ubuntu 16.04 version redis version 3.2.5 I've done a cluster in redis but my question is that whenever i set pool configuration in jedispool parameter it doesn't effect on that here suppose i set setMinIdle parameter to 2 but it can't effect means minimum two connection remain open but after complete execution of program connection is zero(0). also here when JedisCluster object is created five connection automatically done i can't understand why only five connection always establish ? here below is my code snippet

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");    

}

here below is my other class

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 , JedisClusterjc){                                  
        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();                                                                                    
    }
}                                                                                                 
                     

after that connect with redis using this command in my case : redis-cli -p 7000 -c

and check the connection list using command : client list

patel
  • 59
  • 6

0 Answers0