use of redis.clients.jedis.JedisShardInfo in project cachecloud by sohutv.
the class ShardedJedisTest method getKeysDifferentShard.
private List<String> getKeysDifferentShard(ShardedJedis jedis) {
List<String> ret = new ArrayList<String>();
JedisShardInfo first = jedis.getShardInfo("a0");
ret.add("a0");
for (int i = 1; i < 100; ++i) {
JedisShardInfo actual = jedis.getShardInfo("a" + i);
if (actual != first) {
ret.add("a" + i);
break;
}
}
return ret;
}
use of redis.clients.jedis.JedisShardInfo in project cachecloud by sohutv.
the class ShardedJedisTest method testMasterSlaveShardingConsistency.
@Test
public void testMasterSlaveShardingConsistency() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards, Hashing.MURMUR_HASH);
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards, Hashing.MURMUR_HASH);
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
assertEquals(shards.indexOf(jedisShardInfo), otherShards.indexOf(jedisShardInfo2));
}
}
use of redis.clients.jedis.JedisShardInfo in project cachecloud by sohutv.
the class HashingBenchmark method main.
public static void main(String[] args) throws UnknownHostException, IOException {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(), hnp1.getPort());
shard.setPassword("foobared");
shards.add(shard);
shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort());
shard.setPassword("foobared");
shards.add(shard);
ShardedJedis jedis = new ShardedJedis(shards);
Collection<Jedis> allShards = jedis.getAllShards();
for (Jedis j : allShards) {
j.flushAll();
}
long begin = Calendar.getInstance().getTimeInMillis();
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
String key = "foo" + n;
jedis.set(key, "bar" + n);
jedis.get(key);
}
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
jedis.disconnect();
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
use of redis.clients.jedis.JedisShardInfo in project cachecloud by sohutv.
the class ShardedJedisPipelineTest method setUp.
@Before
public void setUp() throws Exception {
Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort());
jedis.auth("foobared");
jedis.flushAll();
jedis.disconnect();
jedis = new Jedis(redis2.getHost(), redis2.getPort());
jedis.auth("foobared");
jedis.flushAll();
jedis.disconnect();
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shardInfo1.setPassword("foobared");
shardInfo2.setPassword("foobared");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(shardInfo1);
shards.add(shardInfo2);
this.jedis = new ShardedJedis(shards);
}
use of redis.clients.jedis.JedisShardInfo in project cachecloud by sohutv.
the class ShardedJedisPoolTest method startWithUrl.
@Test
public void startWithUrl() throws URISyntaxException {
Jedis j = new Jedis("localhost", 6380);
j.auth("foobared");
j.set("foo", "bar");
j = new Jedis("localhost", 6379);
j.auth("foobared");
j.set("foo", "bar");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));
GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
Jedis jedis = jedises[0];
assertEquals("PONG", jedis.ping());
assertEquals("bar", jedis.get("foo"));
jedis = jedises[1];
assertEquals("PONG", jedis.ping());
assertEquals("bar", jedis.get("foo"));
}
Aggregations