org.redisson.api.RScript.Mode Java Examples

The following examples show how to use org.redisson.api.RScript.Mode. 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: RedisQualityAttribute.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
public int convertData(T data) {
    Integer index = indexCache.get(data);
    if (index == null) {
        Number number = script.evalSha(Mode.READ_WRITE, indexSignature, ReturnType.INTEGER, Arrays.asList(indexKey, sizeKey), data);
        index = number.intValue();
        indexCache.put(data, index);
    }
    return index;
}
 
Example #2
Source File: RedissonBatchRxTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test(expected=RedisException.class)
public void testExceptionHandling() {
    RBatchRx batch = redisson.createBatch(batchOptions);
    batch.getMap("test").put("1", "2");
    batch.getScript().eval(Mode.READ_WRITE, "wrong_code", RScript.ReturnType.VALUE);
    sync(batch.execute());
}
 
Example #3
Source File: RedissonBatchTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test(expected=RedisException.class)
public void testExceptionHandling() {
    RBatch batch = redisson.createBatch(batchOptions);
    batch.getMap("test").putAsync("1", "2");
    batch.getScript().evalAsync(Mode.READ_WRITE, "wrong_code", RScript.ReturnType.VALUE);
    batch.execute();
}
 
Example #4
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvalshaAsync() {
    RScript s = redisson.getScript();
    String res = s.scriptLoad("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);
    RFuture<Object> r1 = redisson.getScript().evalShaAsync(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
    Assert.assertEquals("bar", r1.awaitUninterruptibly().getNow());
}
 
Example #5
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvalSha() {
    RScript s = redisson.getScript();
    String res = s.scriptLoad("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 #6
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScriptLoadAsync() {
    redisson.getBucket("foo").set("bar");
    RFuture<String> r = redisson.getScript().scriptLoadAsync("return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r.awaitUninterruptibly().getNow());
    String r1 = redisson.getScript().evalSha(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
    Assert.assertEquals("bar", r1);
}
 
Example #7
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScriptLoad() {
    redisson.getBucket("foo").set("bar");
    String r = redisson.getScript().scriptLoad("return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);
    String r1 = redisson.getScript().evalSha(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
    Assert.assertEquals("bar", r1);
}
 
Example #8
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScriptFlush() {
    redisson.getBucket("foo").set("bar");
    String r = redisson.getScript().scriptLoad("return redis.call('get', 'foo')");
    Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);
    String r1 = redisson.getScript().evalSha(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
    Assert.assertEquals("bar", r1);
    redisson.getScript().scriptFlush();

    try {
        redisson.getScript().evalSha(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
    } catch (Exception e) {
        Assert.assertEquals(RedisException.class, e.getClass());
    }
}
 
Example #9
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScriptEncoding() {
    RScript script = redisson.getScript();
    String value = "test";
    script.eval(RScript.Mode.READ_WRITE, "redis.call('set', KEYS[1], ARGV[1])", RScript.ReturnType.VALUE, Arrays.asList("foo"), value);

    String val = script.eval(RScript.Mode.READ_WRITE, "return redis.call('get', KEYS[1])", RScript.ReturnType.VALUE, Arrays.asList("foo"));
    Assert.assertEquals(value, val);
}
 
Example #10
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEval() {
    RScript script = redisson.getScript(StringCodec.INSTANCE);
    List<Object> res = script.eval(RScript.Mode.READ_ONLY, "return {'1','2','3.3333','foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
    assertThat(res).containsExactly("1", "2", "3.3333", "foo");
}
 
Example #11
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMulti() throws InterruptedException, ExecutionException {
    RLexSortedSet idx2 = redisson.getLexSortedSet("ABCD17436");
    
    Long l = new Long("1506524856000");
    for (int i = 0; i < 100; i++) {
        String s = "DENY" + "\t" + "TESTREDISSON" + "\t"
                + Long.valueOf(l) + "\t" + "helloworld_hongqin";
        idx2.add(s);
        l = l + 1;
    }

    String max = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856099'";
    String min = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856000'";
     String luaScript1= "local d = {}; d[1] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,5); ";
     luaScript1=  luaScript1 + " d[2] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,15); ";
     luaScript1=  luaScript1 + " d[3] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,25); ";
     luaScript1 = luaScript1 + " return d;";
 
     List<List<Object>> objs = redisson.getScript(StringCodec.INSTANCE).eval(RScript.Mode.READ_ONLY,
            luaScript1,
            RScript.ReturnType.MULTI, Collections.emptyList());            
    
    assertThat(objs).hasSize(3);
    assertThat(objs.get(0)).hasSize(5);
    assertThat(objs.get(1)).hasSize(15);
    assertThat(objs.get(2)).hasSize(25);
}
 
Example #12
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 4 votes vote down vote up
@Override
public long currentTime() {
  return redissonClient.getScript()
      .eval(Mode.READ_ONLY, "return redis.call('TIME')[1]*1000", ReturnType.INTEGER);
}
 
Example #13
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testEvalAsync() {
    RScript script = redisson.getScript(StringCodec.INSTANCE);
    RFuture<List<Object>> res = script.evalAsync(RScript.Mode.READ_ONLY, "return {'1','2','3.3333','foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
    assertThat(res.awaitUninterruptibly().getNow()).containsExactly("1", "2", "3.3333", "foo");
}
 
Example #14
Source File: RScriptRx.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Maybe<R> evalSha(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #15
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Mono<R> evalSha(Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #16
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Mono<R> evalSha(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #17
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @return result object
 */
<R> Mono<R> evalSha(Mode mode, String shaDigest, ReturnType returnType);
 
Example #18
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script 
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Mono<R> eval(Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);
 
Example #19
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @return result object
 */
<R> Mono<R> eval(Mode mode, String luaScript, ReturnType returnType);
 
Example #20
Source File: RScriptReactive.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Mono<R> eval(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);
 
Example #21
Source File: RScriptRx.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Maybe<R> evalSha(Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #22
Source File: RScriptRx.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script 
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Maybe<R> eval(Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);
 
Example #23
Source File: RScriptRx.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @return result object
 */
<R> Maybe<R> evalSha(Mode mode, String shaDigest, ReturnType returnType);
 
Example #24
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @return result object
 */
<R> RFuture<R> evalAsync(Mode mode, String luaScript, ReturnType returnType);
 
Example #25
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> RFuture<R> evalAsync(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);
 
Example #26
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script 
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> RFuture<R> evalAsync(Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);
 
Example #27
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @return result object
 */
<R> RFuture<R> evalShaAsync(Mode mode, String shaDigest, ReturnType returnType);
 
Example #28
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> RFuture<R> evalShaAsync(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #29
Source File: RScriptAsync.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script stored in Redis scripts cache by SHA-1 digest
 * 
 * @param <R> - type of result
 * @param mode - execution mode
 * @param shaDigest - SHA-1 digest
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> RFuture<R> evalShaAsync(Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values);
 
Example #30
Source File: RScriptRx.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Executes Lua script
 * 
 * @param <R> - type of result
 * @param key - used to locate Redis node in Cluster which stores cached Lua script 
 * @param mode - execution mode
 * @param luaScript - lua script
 * @param returnType - return type
 * @param keys - keys available through KEYS param in script
 * @param values - values available through VALUES param in script
 * @return result object
 */
<R> Maybe<R> eval(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values);