Java Code Examples for redis.clients.jedis.Pipeline#evalsha()
The following examples show how to use
redis.clients.jedis.Pipeline#evalsha() .
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 |
@Test public void testEvalshaKeyAndArg() { String key = "test"; String arg = "3"; String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; String sha1 = jedis.scriptLoad(script); assertTrue(jedis.scriptExists(sha1)); Pipeline p = jedis.pipelined(); p.set(key, "0"); Response<Object> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg)); p.incr(key); Response<Object> result1 = p.evalsha(sha1, 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 |
@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()); }
Example 3
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void testEvalsha() { String script = "return 'success!'"; String sha1 = jedis.scriptLoad(script); assertTrue(jedis.scriptExists(sha1)); Pipeline p = jedis.pipelined(); Response<Object> result = p.evalsha(sha1); p.sync(); assertEquals("success!", result.get()); }