@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); }
@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)); }
@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()); }