Example #1
0
 @Test
 public void testEval() {
   RScript script = redisson.getScript();
   List<Object> res =
       script.eval(
           RScript.Mode.READ_ONLY,
           "return {1,2,3.3333,'\"foo\"',nil,'bar'}",
           RScript.ReturnType.MULTI,
           Collections.emptyList());
   MatcherAssert.assertThat(res, Matchers.<Object>contains(1L, 2L, 3L, "foo"));
 }
Example #2
0
 @Test
 public void testEvalAsync() {
   RScript script = redisson.getScript();
   Future<List<Object>> res =
       script.evalAsync(
           RScript.Mode.READ_ONLY,
           "return {1,2,3.3333,'\"foo\"',nil,'bar'}",
           RScript.ReturnType.MULTI,
           Collections.emptyList());
   MatcherAssert.assertThat(
       res.awaitUninterruptibly().getNow(), Matchers.<Object>contains(1L, 2L, 3L, "foo"));
 }
Example #3
0
  @Test
  public void testEvalSha() {
    RScript s = redisson.getScript();
    String res = s.scriptLoad(null, "return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res);

    redisson.getBucket("foo").set("bar");
    String r1 =
        s.evalSha(
            Mode.READ_ONLY,
            "282297a0228f48cd3fc6a55de6316f31422f5d17",
            RScript.ReturnType.VALUE,
            Collections.emptyList());
    Assert.assertEquals("bar", r1);
  }
Example #4
0
  @Test
  public void testScriptExists() {
    RScript s = redisson.getScript();
    String r = s.scriptLoad(null, "return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);

    List<Boolean> r1 = s.scriptExists(null, r);
    Assert.assertEquals(1, r1.size());
    Assert.assertTrue(r1.get(0));

    s.scriptFlush();

    List<Boolean> r2 = s.scriptExists(null, r);
    Assert.assertEquals(1, r2.size());
    Assert.assertFalse(r2.get(0));
  }
Example #5
0
  @Test
  public void testEvalshaAsync() {
    RScript s = redisson.getScript();
    String res = s.scriptLoad(null, "return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res);

    redisson.getBucket("foo").set("bar");
    String r =
        redisson
            .getScript()
            .eval(Mode.READ_ONLY, "return redis.call('get', 'foo')", RScript.ReturnType.VALUE);
    Assert.assertEquals("bar", r);
    Future<Object> r1 =
        redisson
            .getScript()
            .evalShaAsync(
                Mode.READ_ONLY,
                "282297a0228f48cd3fc6a55de6316f31422f5d17",
                RScript.ReturnType.VALUE,
                Collections.emptyList());
    Assert.assertEquals("bar", r1.awaitUninterruptibly().getNow());
  }