本文整理汇总了Java中redis.clients.jedis.Pipeline.evalsha方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.evalsha方法的具体用法?Java Pipeline.evalsha怎么用?Java Pipeline.evalsha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.evalsha方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEvalshaKeyAndArg
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@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());
}
示例2: testEvalshaKeyAndArgWithBinary
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@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());
}
示例3: testEvalsha
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@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());
}
示例4: doOrderNotSafe
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* 当无竞争情况时下单
*
* @param bracketMap bracket
* @param jedis redis连接
*/
public void doOrderNotSafe(Map<String, String> bracketMap, String userId, String bracketId, Jedis jedis) {
int size = bracketMap.size();
String sha;
if (this.scriptSHA.get(size) == null) {
StringBuilder updateBuilder = new StringBuilder();
for (int i = 1; i <= size; i++) {
updateBuilder.append(" redis.call('decrby',KEYS[").append(i).append("],ARGV[").append(i).append("])");
}
sha = jedis.scriptLoad(updateBuilder.substring(1));
this.scriptSHA.put(3 + size, sha);
} else {
sha = this.scriptSHA.get(3 + size);
}
List<String> keyList = new ArrayList<>();
List<String> paramList = new ArrayList<>();
for (String key : bracketMap.keySet()) {
keyList.add(Const.FOOD_STOCKS + key);
paramList.add(bracketMap.get(key));
}
Pipeline pipeline = jedis.pipelined();
pipeline.evalsha(sha, keyList, paramList);
pipeline.hdel(Const.BRACKET_ID_BUFFER, bracketId);
pipeline.hset(Const.ORDER_ID_BUFFER, userId, bracketId);
pipeline.sync();
}