Search in sources :

Example 6 with ShardedJedisPipeline

use of redis.clients.jedis.ShardedJedisPipeline 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 7 with ShardedJedisPipeline

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

the class ShardedJedisPoolTest method returnResourceShouldResetState.

@Test
public void returnResourceShouldResetState() throws URISyntaxException {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    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")));
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("pipelined", String.valueOf(0));
    jedis.set("pipelined2", String.valueOf(0));
    ShardedJedisPipeline pipeline = jedis.pipelined();
    pipeline.incr("pipelined");
    pipeline.incr("pipelined2");
    jedis.resetState();
    pipeline = jedis.pipelined();
    pipeline.incr("pipelined");
    pipeline.incr("pipelined2");
    List<Object> results = pipeline.syncAndReturnAll();
    assertEquals(2, results.size());
    jedis.close();
    pool.destroy();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Example 8 with ShardedJedisPipeline

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

the class ShardedJedisPipelineTest method pipelineResponseWithinPipeline.

@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
    jedis.set("string", "foo");
    ShardedJedisPipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    string.get();
    p.sync();
}
Also used : ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) Test(org.junit.Test)

Example 9 with ShardedJedisPipeline

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

the class ShardedJedisPipelineTest method canRetrieveUnsetKey.

@Test
public void canRetrieveUnsetKey() {
    ShardedJedisPipeline p = jedis.pipelined();
    Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
    p.sync();
    assertNull(shouldNotExist.get());
}
Also used : ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) Test(org.junit.Test)

Example 10 with ShardedJedisPipeline

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

the class ShardedJedisPipelineTest method pipelineResponse.

@Test
public void pipelineResponse() {
    jedis.set("string", "foo");
    jedis.lpush("list", "foo");
    jedis.hset("hash", "foo", "bar");
    jedis.zadd("zset", 1, "foo");
    jedis.sadd("set", "foo");
    ShardedJedisPipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    Response<Long> del = p.del("string");
    Response<String> emptyString = p.get("string");
    Response<String> list = p.lpop("list");
    Response<String> hash = p.hget("hash", "foo");
    Response<Set<String>> zset = p.zrange("zset", 0, -1);
    Response<String> set = p.spop("set");
    Response<Boolean> blist = p.exists("list");
    Response<Double> zincrby = p.zincrby("zset", 1, "foo");
    Response<Long> zcard = p.zcard("zset");
    p.lpush("list", "bar");
    Response<List<String>> lrange = p.lrange("list", 0, -1);
    Response<Map<String, String>> hgetAll = p.hgetAll("hash");
    p.sadd("set", "foo");
    Response<Set<String>> smembers = p.smembers("set");
    Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0, -1);
    p.sync();
    assertEquals("foo", string.get());
    assertEquals(Long.valueOf(1), del.get());
    assertNull(emptyString.get());
    assertEquals("foo", list.get());
    assertEquals("bar", hash.get());
    assertEquals("foo", zset.get().iterator().next());
    assertEquals("foo", set.get());
    assertFalse(blist.get());
    assertEquals(Double.valueOf(2), zincrby.get());
    assertEquals(Long.valueOf(1), zcard.get());
    assertEquals(1, lrange.get().size());
    assertNotNull(hgetAll.get().get("foo"));
    assertEquals(1, smembers.get().size());
    assertEquals(1, zrangeWithScores.get().size());
}
Also used : Set(java.util.Set) ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)12 ArrayList (java.util.ArrayList)6 JedisShardInfo (redis.clients.jedis.JedisShardInfo)4 ShardedJedis (redis.clients.jedis.ShardedJedis)4 URI (java.net.URI)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)2 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)2