use of redis.clients.jedis.Pipeline in project jedis by xetorthio.
the class PipeliningTest method pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti.
@Test(expected = JedisDataException.class)
public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti() {
Pipeline pipeline = jedis.pipelined();
pipeline.discard();
}
use of redis.clients.jedis.Pipeline in project jedis by xetorthio.
the class PipeliningTest 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");
jedis.setrange("setrange", 0, "0123456789");
byte[] bytesForSetRange = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange);
Pipeline p = jedis.pipelined();
Response<String> string = 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);
Response<String> getrange = p.getrange("setrange", 1, 3);
Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(), 6, 8);
p.sync();
assertEquals("foo", string.get());
assertEquals("foo", list.get());
assertEquals("bar", hash.get());
assertEquals("foo", zset.get().iterator().next());
assertEquals("foo", set.get());
assertEquals(false, 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());
assertEquals("123", getrange.get());
byte[] expectedGetRangeBytes = { 6, 7, 8 };
assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get());
}
use of redis.clients.jedis.Pipeline in project jedis by xetorthio.
the class PipeliningTest method canRetrieveUnsetKey.
@Test
public void canRetrieveUnsetKey() {
Pipeline p = jedis.pipelined();
Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
p.sync();
assertNull(shouldNotExist.get());
}
use of redis.clients.jedis.Pipeline in project jedis by xetorthio.
the class PipeliningTest method testReuseJedisWhenPipelineIsEmpty.
@Test
public void testReuseJedisWhenPipelineIsEmpty() {
Pipeline pipeline = jedis.pipelined();
pipeline.set("foo", "3");
pipeline.sync();
String result = jedis.get("foo");
assertEquals(result, "3");
}
use of redis.clients.jedis.Pipeline in project jedis by xetorthio.
the class PipeliningTest method testEvalshaKeyAndArgWithBinary.
@Test
public void testEvalshaKeyAndArgWithBinary() {
byte[] bKey = SafeEncoder.encode("test");
byte[] bArg = SafeEncoder.encode("3");
String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
byte[] bScript = SafeEncoder.encode(script);
byte[] bSha1 = jedis.scriptLoad(bScript);
assertTrue(jedis.scriptExists(bSha1) == 1);
Pipeline p = jedis.pipelined();
p.set(bKey, SafeEncoder.encode("0"));
Response<Object> result0 = p.evalsha(bSha1, Arrays.asList(bKey), Arrays.asList(bArg));
p.incr(bKey);
Response<Object> result1 = p.evalsha(bSha1, Arrays.asList(bKey), Arrays.asList(bArg));
Response<byte[]> result2 = p.get(bKey);
p.sync();
assertNull(result0.get());
assertNull(result1.get());
assertArrayEquals(SafeEncoder.encode("13"), result2.get());
}
Aggregations