use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.
the class ShardedJedisTest method testAvoidLeaksUponDisconnect.
/**
* Test for "Issue - BinaryShardedJedis.disconnect() may occur memory leak". You can find more
* detailed information at https://github.com/xetorthio/jedis/issues/808
* @throws InterruptedException
*/
@Test
public void testAvoidLeaksUponDisconnect() throws InterruptedException {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(2);
// 6379
JedisShardInfo shard1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
shard1.setPassword("foobared");
shards.add(shard1);
// 6380
JedisShardInfo shard2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shard2.setPassword("foobared");
shards.add(shard2);
@SuppressWarnings("resource") ShardedJedis shardedJedis = new ShardedJedis(shards);
// establish the connection for two redis servers
shardedJedis.set("a", "bar");
JedisShardInfo ak = shardedJedis.getShardInfo("a");
assertEquals(shard2, ak);
shardedJedis.set("b", "bar1");
JedisShardInfo bk = shardedJedis.getShardInfo("b");
assertEquals(shard1, bk);
// We set a name to the instance so it's easy to find it
Iterator<Jedis> it = shardedJedis.getAllShards().iterator();
Jedis deadClient = it.next();
deadClient.clientSetname("DEAD");
ClientKillerUtil.killClient(deadClient, "DEAD");
assertEquals(true, deadClient.isConnected());
assertEquals(false, deadClient.getClient().getSocket().isClosed());
// normal - not found
assertEquals(false, deadClient.getClient().isBroken());
shardedJedis.disconnect();
assertEquals(false, deadClient.isConnected());
assertEquals(true, deadClient.getClient().getSocket().isClosed());
assertEquals(true, deadClient.getClient().isBroken());
Jedis jedis2 = it.next();
assertEquals(false, jedis2.isConnected());
assertEquals(true, jedis2.getClient().getSocket().isClosed());
assertEquals(false, jedis2.getClient().isBroken());
}
use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.
the class ShardedJedisTest method trySharding.
@Test
public void trySharding() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
JedisShardInfo si = new JedisShardInfo(redis1.getHost(), redis1.getPort());
si.setPassword("foobared");
shards.add(si);
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
si.setPassword("foobared");
shards.add(si);
ShardedJedis jedis = new ShardedJedis(shards);
jedis.set("a", "bar");
JedisShardInfo s1 = jedis.getShardInfo("a");
jedis.set("b", "bar1");
JedisShardInfo s2 = jedis.getShardInfo("b");
jedis.disconnect();
Jedis j = new Jedis(s1.getHost(), s1.getPort());
j.auth("foobared");
assertEquals("bar", j.get("a"));
j.disconnect();
j = new Jedis(s2.getHost(), s2.getPort());
j.auth("foobared");
assertEquals("bar1", j.get("b"));
j.disconnect();
}
use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.
the class ShardedJedisTest method checkCloseable.
@Test
public void checkCloseable() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
shards.get(0).setPassword("foobared");
shards.get(1).setPassword("foobared");
ShardedJedis jedisShard = new ShardedJedis(shards);
try {
jedisShard.set("shard_closeable", "true");
} finally {
jedisShard.close();
}
for (Jedis jedis : jedisShard.getAllShards()) {
assertTrue(!jedis.isConnected());
}
}
use of redis.clients.jedis.ShardedJedis in project oxCore by GluuFederation.
the class RedisShardedProvider method put.
@Override
public void put(int expirationInSeconds, String key, Object object) {
ShardedJedis jedis = pool.getResource();
try {
String status = jedis.setex(key.getBytes(), expirationInSeconds, SerializationUtils.serialize((Serializable) object));
LOG.trace("put - key: " + key + ", status: " + status);
} finally {
jedis.close();
}
}
use of redis.clients.jedis.ShardedJedis in project oxCore by GluuFederation.
the class RedisShardedProvider method remove.
@Override
public void remove(String key) {
ShardedJedis jedis = pool.getResource();
try {
Long entriesRemoved = jedis.del(key.getBytes());
LOG.trace("remove - key: " + key + ", entriesRemoved: " + entriesRemoved);
} finally {
jedis.close();
}
}
Aggregations