|
|
|
@ -39,10 +39,17 @@ import io.netty.buffer.ByteBuf;
|
|
|
|
|
*/
|
|
|
|
|
public class RedissonScript implements RScript {
|
|
|
|
|
|
|
|
|
|
private final Codec codec;
|
|
|
|
|
private final CommandAsyncExecutor commandExecutor;
|
|
|
|
|
|
|
|
|
|
public RedissonScript(CommandAsyncExecutor commandExecutor) {
|
|
|
|
|
this.commandExecutor = commandExecutor;
|
|
|
|
|
this.codec = commandExecutor.getConnectionManager().getCodec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RedissonScript(CommandAsyncExecutor commandExecutor, Codec codec) {
|
|
|
|
|
this.commandExecutor = commandExecutor;
|
|
|
|
|
this.codec = codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -70,88 +77,68 @@ public class RedissonScript implements RScript {
|
|
|
|
|
}, luaScript);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<String> scriptLoadAsync(String key, String luaScript) {
|
|
|
|
|
return commandExecutor.writeAsync(key, RedisCommands.SCRIPT_LOAD, luaScript);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R eval(Mode mode, String luaScript, ReturnType returnType) {
|
|
|
|
|
return eval(null, mode, commandExecutor.getConnectionManager().getCodec(), luaScript, returnType);
|
|
|
|
|
return eval(mode, luaScript, returnType, Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R eval(Mode mode, Codec codec, String luaScript, ReturnType returnType) {
|
|
|
|
|
return eval(null, mode, codec, luaScript, returnType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public <R> R eval(String key, Mode mode, Codec codec, String luaScript, ReturnType returnType) {
|
|
|
|
|
return eval(key, mode, codec, luaScript, returnType, Collections.emptyList());
|
|
|
|
|
RedissonScript script = new RedissonScript(commandExecutor, codec);
|
|
|
|
|
return script.eval(mode, luaScript, returnType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R eval(Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return eval(null, mode, commandExecutor.getConnectionManager().getCodec(), luaScript, returnType, keys, values);
|
|
|
|
|
return eval(null, mode, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R eval(Mode mode, Codec codec, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return eval(null, mode, codec, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> R eval(String key, Mode mode, Codec codec, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return (R) commandExecutor.get(evalAsync(key, mode, codec, luaScript, returnType, keys, values));
|
|
|
|
|
RedissonScript script = new RedissonScript(commandExecutor, codec);
|
|
|
|
|
return script.eval(mode, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> RFuture<R> evalAsync(Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return evalAsync(null, mode, commandExecutor.getConnectionManager().getCodec(), luaScript, returnType, keys, values);
|
|
|
|
|
return evalAsync(null, mode, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> RFuture<R> evalAsync(Mode mode, Codec codec, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return evalAsync(null, mode, codec, luaScript, returnType, keys, values);
|
|
|
|
|
RedissonScript script = new RedissonScript(commandExecutor, codec);
|
|
|
|
|
return script.evalAsync(mode, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> RFuture<R> evalAsync(String key, Mode mode, Codec codec, String luaScript, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
if (mode == Mode.READ_ONLY) {
|
|
|
|
|
return commandExecutor.evalReadAsync(key, codec, returnType.getCommand(), luaScript, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
return commandExecutor.evalWriteAsync(key, codec, returnType.getCommand(), luaScript, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
RedissonScript script = new RedissonScript(commandExecutor, codec);
|
|
|
|
|
return script.evalAsync(key, mode, luaScript, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R evalSha(Mode mode, String shaDigest, ReturnType returnType) {
|
|
|
|
|
return evalSha(null, mode, commandExecutor.getConnectionManager().getCodec(), shaDigest, returnType);
|
|
|
|
|
return evalSha(null, mode, shaDigest, returnType, Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R evalSha(Mode mode, Codec codec, String shaDigest, ReturnType returnType) {
|
|
|
|
|
return evalSha(null, mode, codec, shaDigest, returnType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> R evalSha(String key, Mode mode, String shaDigest, ReturnType returnType) {
|
|
|
|
|
return evalSha(key, mode, commandExecutor.getConnectionManager().getCodec(), shaDigest, returnType, Collections.emptyList());
|
|
|
|
|
return evalSha(mode, codec, shaDigest, returnType, Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> R evalSha(String key, Mode mode, Codec codec, String shaDigest, ReturnType returnType) {
|
|
|
|
|
return evalSha(key, mode, codec, shaDigest, returnType, Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R evalSha(Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return evalSha(null, mode, commandExecutor.getConnectionManager().getCodec(), shaDigest, returnType, keys, values);
|
|
|
|
|
return evalSha(null, mode, shaDigest, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R evalSha(Mode mode, Codec codec, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return evalSha(null, mode, codec, shaDigest, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> R evalSha(String key, Mode mode, Codec codec, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
return (R) commandExecutor.get(evalShaAsync(key, mode, codec, shaDigest, returnType, keys, values));
|
|
|
|
|
return (R) commandExecutor.get(evalShaAsync(null, mode, codec, shaDigest, returnType, keys, values));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -165,11 +152,8 @@ public class RedissonScript implements RScript {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> RFuture<R> evalShaAsync(String key, Mode mode, Codec codec, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) {
|
|
|
|
|
RedisCommand command = new RedisCommand(returnType.getCommand(), "EVALSHA");
|
|
|
|
|
if (mode == Mode.READ_ONLY) {
|
|
|
|
|
return commandExecutor.evalReadAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
return commandExecutor.evalWriteAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
RedissonScript script = new RedissonScript(commandExecutor, codec);
|
|
|
|
|
return script.evalShaAsync(key, mode, shaDigest, returnType, keys, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -238,7 +222,6 @@ public class RedissonScript implements RScript {
|
|
|
|
|
return commandExecutor.writeAllAsync(RedisCommands.SCRIPT_FLUSH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
public RFuture<Void> scriptFlushAsync(String key) {
|
|
|
|
|
return commandExecutor.writeAsync(key, RedisCommands.SCRIPT_FLUSH);
|
|
|
|
|
}
|
|
|
|
@ -286,4 +269,35 @@ public class RedissonScript implements RScript {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> RFuture<R> evalShaAsync(String key, Mode mode, String shaDigest, ReturnType returnType,
|
|
|
|
|
List<Object> keys, Object... values) {
|
|
|
|
|
RedisCommand command = new RedisCommand(returnType.getCommand(), "EVALSHA");
|
|
|
|
|
if (mode == Mode.READ_ONLY) {
|
|
|
|
|
return commandExecutor.evalReadAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
return commandExecutor.evalWriteAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> RFuture<R> evalAsync(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys,
|
|
|
|
|
Object... values) {
|
|
|
|
|
if (mode == Mode.READ_ONLY) {
|
|
|
|
|
return commandExecutor.evalReadAsync(key, codec, returnType.getCommand(), luaScript, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
return commandExecutor.evalWriteAsync(key, codec, returnType.getCommand(), luaScript, keys, encode(Arrays.asList(values), codec).toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R evalSha(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys,
|
|
|
|
|
Object... values) {
|
|
|
|
|
return commandExecutor.get((RFuture<R>)evalShaAsync(key, mode, shaDigest, returnType, keys, values));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> R eval(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys,
|
|
|
|
|
Object... values) {
|
|
|
|
|
return commandExecutor.get((RFuture<R>)evalAsync(key, mode, luaScript, returnType, keys, values));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|