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 73505a1 commit 5c636bb
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -21,6 +22,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 @@ -119,6 +121,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
Original file line number Diff line number Diff line change
@@ -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); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 5c636bb

Please sign in to comment.