Search in sources :

Example 11 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project jedis by xetorthio.

the class ShardedJedisTest method tryShardingWithMurmure.

@Test
public void tryShardingWithMurmure() {
    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, Hashing.MURMUR_HASH);
    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();
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 12 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project jedis by xetorthio.

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();
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 13 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.

the class ShardedJedisPipelineTest method testSyncWithNoCommandQueued.

@Test
public void testSyncWithNoCommandQueued() {
    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);
    ShardedJedis jedis2 = new ShardedJedis(shards);
    ShardedJedisPipeline pipeline = jedis2.pipelined();
    pipeline.sync();
    jedis2.close();
    jedis2 = new ShardedJedis(shards);
    pipeline = jedis2.pipelined();
    List<Object> resp = pipeline.syncAndReturnAll();
    assertTrue(resp.isEmpty());
    jedis2.close();
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 14 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.

the class ShardedJedisPoolTest method shouldNotShareInstances.

@Test
public void shouldNotShareInstances() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(2);
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis j1 = pool.getResource();
    ShardedJedis j2 = pool.getResource();
    assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Example 15 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project cachecloud by sohutv.

the class ShardedJedisPoolTest method checkCloseableConnections.

@Test
public void checkCloseableConnections() throws Exception {
    ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    jedis.close();
    pool.close();
    assertTrue(pool.isClosed());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Aggregations

ShardedJedis (redis.clients.jedis.ShardedJedis)45 Test (org.junit.Test)36 JedisShardInfo (redis.clients.jedis.JedisShardInfo)24 ArrayList (java.util.ArrayList)22 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)22 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)22 Jedis (redis.clients.jedis.Jedis)14 URI (java.net.URI)4 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)4 Serializable (java.io.Serializable)2 Before (org.junit.Before)2