|
public static void main(String[] args) {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(2);
HostAndPort hp0 = new HostAndPort( "10.8.24.112", 7001);
HostAndPort hp1 = new HostAndPort( "10.8.24.112", 7002);
HostAndPort hp2 = new HostAndPort( "10.8.24.112", 7003);
HostAndPort hp3 = new HostAndPort( "10.8.24.112", 7004);
HostAndPort hp4 = new HostAndPort( "10.8.24.112", 7005);
HostAndPort hp5 = new HostAndPort( "10.8.24.112", 7006);
Set hps = new HashSet();
hps.add( hp0);
hps.add( hp1);
hps.add( hp2);
hps.add( hp3);
hps.add( hp4);
hps.add( hp5);
// 超时,最大的转发数,最大链接数,最小链接数都会影响到集群
JedisCluster jedisCluster = new JedisCluster( hps, 5000, 10, config);
long start = System. currentTimeMillis();
for ( int i = 0; i < 100; i++) {
jedisCluster.set( "sn" + i, "n" + i);
}
long end = System. currentTimeMillis();
System. out.println( "Simple @ Sharding Set : " + (end - start) / 10000);
for ( int i = 0; i < 1000; i++) {
System. out.println( jedisCluster.get( "sn" + i));
}
try {
jedisCluster.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
|
|
|