import java.util.HashSet;
import java.util.Set;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;
public class redis_cluster_300 {
private static JedisCluster jc;
static {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(100);
config.setMaxIdle(100);
config.setMinIdle(100);
config.setMaxWaitMillis(6 * 1000);
// config.setMaxWait(1000 * 4);
config.setTestOnBorrow(true);
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7000));
// jedisClusterNodes.add(new HostAndPort("192.168.56.101", 7001));
// jedisClusterNodes.add(new HostAndPort("192.168.56.101", 7002));
// jedisClusterNodes.add(new HostAndPort("192.168.56.101", 7003));
// / jedisClusterNodes.add(new HostAndPort("192.168.56.101", 7004));
// jedisClusterNodes.add(new HostAndPort("192.168.56.101", 7005));
jc = new JedisCluster(jedisClusterNodes, 2000, 2, config);
// logger.info("redis ip:"+Constant.REDIS_IP+", port:"+Constant.REDIS_PORT);
}
public static void main(String[] args) {
System.out.println("");
try {
for (int i = 0; i < 1000; i++) {
long t1 = System.currentTimeMillis();
jc.set("" + i, "" + i);
long t2 = System.currentTimeMillis();
String value = jc.get("" + i);
long t3 = System.currentTimeMillis();
System.out.println("" + value);
System.out.println((t2 - t1) + "mills");
System.out.println((t3 - t2) + "mills");
}
// jc.set("foo", "bar");
// list
for (int i = 0; i < 1000; i++) {
long t1 = System.currentTimeMillis();
jc.lset("list", i, "list_"+i);
long t2 = System.currentTimeMillis();
String value = jc.lindex("list", i);
long t3 = System.currentTimeMillis();
System.out.println("" + value);
System.out.println((t2 - t1) + "mills");
System.out.println((t3 - t2) + "mills");
}
//hash
for (int i = 0; i < 1000; i++) {
long t1 = System.currentTimeMillis();
jc.hset("hash", ""+i, "hash_"+i);
//jc.lset("list", i, "list_"+i);
long t2 = System.currentTimeMillis();
//String value = jc.lindex("list", i);
String value=jc.hget("hash", ""+i);
long t3 = System.currentTimeMillis();
System.out.println("" + value);
System.out.println((t2 - t1) + "mills");
System.out.println((t3 - t2) + "mills");
}
} catch (Exception e) {
System.out.println(e);
} finally {
//
}
}
}