Skip to content

Commit

Permalink
Improvement (issue #1352): (#1353)
Browse files Browse the repository at this point in the history
evalsha should throw specialized exception if redis answers with NOSCRIPT message.
  • Loading branch information
smagellan authored and marcosnils committed Jul 20, 2016
1 parent 252dd87 commit 0551ca5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/Protocol.java
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.exceptions.JedisNoScriptException;
import redis.clients.util.RedisInputStream;
import redis.clients.util.RedisOutputStream;
import redis.clients.util.SafeEncoder;
Expand All @@ -22,6 +23,7 @@ public final class Protocol {
private static final String MOVED_RESPONSE = "MOVED";
private static final String CLUSTERDOWN_RESPONSE = "CLUSTERDOWN";
private static final String BUSY_RESPONSE = "BUSY";
private static final String NOSCRIPT_RESPONSE = "NOSCRIPT";

public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 6379;
Expand Down Expand Up @@ -120,6 +122,8 @@ private static void processError(final RedisInputStream is) {
throw new JedisClusterException(message);
} else if (message.startsWith(BUSY_RESPONSE)) {
throw new JedisBusyException(message);
} else if (message.startsWith(NOSCRIPT_RESPONSE) ) {
throw new JedisNoScriptException(message);
}
throw new JedisDataException(message);
}
Expand Down
@@ -0,0 +1,11 @@
package redis.clients.jedis.exceptions;

public class JedisNoScriptException extends JedisDataException {
private static final long serialVersionUID = 4674378093072060731L;

public JedisNoScriptException(final String message) { super(message); }

public JedisNoScriptException(final Throwable cause) { super(cause); }

public JedisNoScriptException(final String message, final Throwable cause) { super(message, cause); }
}
Expand Up @@ -18,6 +18,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisNoScriptException;
import redis.clients.jedis.tests.utils.ClientKillerUtil;
import redis.clients.util.SafeEncoder;

Expand Down Expand Up @@ -127,7 +128,7 @@ public void evalsha() {
assertEquals("bar", result);
}

@Test(expected = JedisDataException.class)
@Test(expected = JedisNoScriptException.class)
public void evalshaShaNotFound() {
jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff");
}
Expand Down

0 comments on commit 0551ca5

Please sign in to comment.