diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index 61c599d1852..a8dd57a0fa2 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -1492,32 +1492,29 @@ public Object eval(final String script, final int keyCount, final String... para public Object execute(Jedis connection) { return connection.eval(script, keyCount, params); } - }.runScript(params); + }.runScript(keyCount, params); } @Override - public Object eval(final String script, final List keys, final List args) { + public Object eval(final String script, final String key) { return new JedisClusterCommand(connectionHandler, timeout, maxRedirections) { @Override public Object execute(Jedis connection) { - return connection.eval(script, keys, args); + return connection.eval(script); } - }.runScript(keys.toArray(new String[keys.size()])); + }.runScript(1, key); } - /** - * This method will not execute the script because no key is provided. - */ @Override - public Object eval(final String script) { + public Object eval(final String script, final List keys, final List args) { return new JedisClusterCommand(connectionHandler, timeout, maxRedirections) { @Override public Object execute(Jedis connection) { - return connection.eval(script); + return connection.eval(script, keys, args); } - }.runScript(null); + }.runScript(keys.size(), keys.toArray(new String[keys.size()])); } @Override @@ -1528,7 +1525,7 @@ public Object evalsha(final String sha1, final int keyCount, final String... par public Object execute(Jedis connection) { return connection.evalsha(sha1, keyCount, params); } - }.runScript(params); + }.runScript(keyCount, params); } @Override @@ -1539,35 +1536,18 @@ public Object evalsha(final String sha1, final List keys, final List(connectionHandler, timeout, maxRedirections) { @Override public Object execute(Jedis connection) { - return connection.evalsha(sha1); - } - }.runScript(null); - } - - /** - * This method will not execute the script because no key is provided. - */ - @Override - public Boolean scriptExists(final String sha1) { - return new JedisClusterCommand(connectionHandler, - timeout, maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.scriptExists(sha1); + return connection.evalsha(script); } - }.runScript(null); + }.runScript(1, key); } @Override @@ -1578,21 +1558,7 @@ public Boolean scriptExists(final String sha1, final String key) { public Boolean execute(Jedis connection) { return connection.scriptExists(sha1); } - }.runScript(key); - } - - /** - * This method will not execute the script because no key is provided. - */ - @Override - public List scriptExists(final String... sha1) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.scriptExists(sha1); - } - }.runScript(null); + }.runScript(1,key); } @Override @@ -1603,21 +1569,7 @@ public List scriptExists(final String key, final String... sha1) { public List execute(Jedis connection) { return connection.scriptExists(sha1); } - }.runScript(key); - } - - /** - * This method will not execute the script because no key is provided. - */ - @Override - public String scriptLoad(final String script) { - return new JedisClusterCommand(connectionHandler, - timeout, maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.scriptLoad(script); - } - }.runScript(null); + }.runScript(1, key); } @Override @@ -1628,7 +1580,7 @@ public String scriptLoad(final String script, final String key) { public String execute(Jedis connection) { return connection.scriptLoad(script); } - }.runScript(key); + }.runScript(1, key); } } diff --git a/src/main/java/redis/clients/jedis/JedisClusterCommand.java b/src/main/java/redis/clients/jedis/JedisClusterCommand.java index 91f34f25ead..5cc00a9908b 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterCommand.java +++ b/src/main/java/redis/clients/jedis/JedisClusterCommand.java @@ -33,21 +33,21 @@ public T run(String key) { return runWithRetries(key, this.redirections, false, false); } - public T runScript(String... keys) { + public T runScript(int keyCount, String... keys) { if (keys == null || keys.length == 0) { throw new JedisClusterException( "No way to dispatch this command to Redis Cluster."); } - // For multiple keys, only execute if they all share the + // For multiple keys, only execute if they all share the // same connection slot. if (keys.length > 1) { int slot = JedisClusterCRC16.getSlot(keys[0]); - for (int i = 1; i < keys.length; i++) { + for (int i = 1; i < keyCount; i++) { int nextSlot = JedisClusterCRC16.getSlot(keys[i]); if (slot != nextSlot) { throw new JedisClusterException( - "No way to dispatch this command to Redis Cluster" + + "No way to dispatch this command to Redis Cluster " + "because keys have different slots."); } } diff --git a/src/main/java/redis/clients/jedis/JedisClusterScriptingCommands.java b/src/main/java/redis/clients/jedis/JedisClusterScriptingCommands.java index 2f2e7c4e481..22a49cdb06b 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterScriptingCommands.java +++ b/src/main/java/redis/clients/jedis/JedisClusterScriptingCommands.java @@ -2,7 +2,19 @@ import java.util.List; -public interface JedisClusterScriptingCommands extends ScriptingCommands{ +public interface JedisClusterScriptingCommands { + Object eval(String script, int keyCount, String... params); + + Object eval(String script, List keys, List args); + + Object eval(String script, String key); + + Object evalsha(String script, String key); + + Object evalsha(String sha1, List keys, List args); + + Object evalsha(String sha1, int keyCount, String... params); + Boolean scriptExists(String sha1, String key); List scriptExists(String key, String... sha1);