Java Code Examples for redis.clients.jedis.Pipeline#eval()

The following examples show how to use redis.clients.jedis.Pipeline#eval() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvalKeyAndArg() {
  String key = "test";
  String arg = "3";
  String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";

  Pipeline p = jedis.pipelined();
  p.set(key, "0");
  Response<Object> result0 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
  p.incr(key);
  Response<Object> result1 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
  Response<String> result2 = p.get(key);
  p.sync();

  assertNull(result0.get());
  assertNull(result1.get());
  assertEquals("13", result2.get());
}
 
Example 2
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvalKeyAndArgWithBinary() {
  // binary
  byte[] bKey = SafeEncoder.encode("test");
  byte[] bArg = SafeEncoder.encode("3");
  byte[] bScript = SafeEncoder
      .encode("redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])");

  Pipeline bP = jedis.pipelined();
  bP.set(bKey, SafeEncoder.encode("0"));
  Response<Object> bResult0 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  bP.incr(bKey);
  Response<Object> bResult1 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  Response<byte[]> bResult2 = bP.get(bKey);
  bP.sync();

  assertNull(bResult0.get());
  assertNull(bResult1.get());
  assertArrayEquals(SafeEncoder.encode("13"), bResult2.get());
}
 
Example 3
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testEval() {
  String script = "return 'success!'";

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(script);
  p.sync();

  assertEquals("success!", result.get());
}
 
Example 4
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvalWithBinary() {
  String script = "return 'success!'";

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(SafeEncoder.encode(script));
  p.sync();

  assertArrayEquals(SafeEncoder.encode("success!"), (byte[]) result.get());
}
 
Example 5
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvalNestedLists() {
  String script = "return { {KEYS[1]} , {2} }";

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(script, 1, "key1");
  p.sync();

  List<?> results = (List<?>) result.get();
  assertThat((List<String>) results.get(0), listWithItem("key1"));
  assertThat((List<Long>) results.get(1), listWithItem(2L));
}
 
Example 6
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvalNestedListsWithBinary() {
  byte[] bScript = SafeEncoder.encode("return { {KEYS[1]} , {2} }");
  byte[] bKey = SafeEncoder.encode("key1");

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(bScript, 1, bKey);
  p.sync();

  List<?> results = (List<?>) result.get();
  assertThat((List<byte[]>) results.get(0), listWithItem(bKey));
  assertThat((List<Long>) results.get(1), listWithItem(2L));
}