Skip to content

Commit 8f62c4c

Browse files
Tobias Schuhmachermarcosnils
authored andcommitted
Intoduce dedicated excpetion for Redis error "busy"
* Introduce JedisRedisBusyException * Add test for JedisRedisBusyException in case of redis error "busy" If redis returns a message starting with "-BUSY" a JedisRedisBusyException containing that message is thrown. * Harmonize name of constant with those of other reponses * Rename exception class to comply with conventions Rename JedisRedisBusyException to JedisBusyException.
1 parent 21fded3 commit 8f62c4c

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/main/java/redis/clients/jedis/Protocol.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import redis.clients.jedis.commands.ProtocolCommand;
88
import redis.clients.jedis.exceptions.JedisAskDataException;
9+
import redis.clients.jedis.exceptions.JedisBusyException;
910
import redis.clients.jedis.exceptions.JedisClusterException;
1011
import redis.clients.jedis.exceptions.JedisConnectionException;
1112
import redis.clients.jedis.exceptions.JedisDataException;
@@ -19,6 +20,8 @@ public final class Protocol {
1920
private static final String ASK_RESPONSE = "ASK";
2021
private static final String MOVED_RESPONSE = "MOVED";
2122
private static final String CLUSTERDOWN_RESPONSE = "CLUSTERDOWN";
23+
private static final String BUSY_RESPONSE = "BUSY";
24+
2225
public static final String DEFAULT_HOST = "localhost";
2326
public static final int DEFAULT_PORT = 6379;
2427
public static final int DEFAULT_SENTINEL_PORT = 26379;
@@ -114,6 +117,8 @@ private static void processError(final RedisInputStream is) {
114117
Integer.valueOf(askInfo[2])), Integer.valueOf(askInfo[0]));
115118
} else if (message.startsWith(CLUSTERDOWN_RESPONSE)) {
116119
throw new JedisClusterException(message);
120+
} else if (message.startsWith(BUSY_RESPONSE)) {
121+
throw new JedisBusyException(message);
117122
}
118123
throw new JedisDataException(message);
119124
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package redis.clients.jedis.exceptions;
2+
3+
public class JedisBusyException extends JedisDataException {
4+
5+
private static final long serialVersionUID = 3992655220229243478L;
6+
7+
public JedisBusyException(final String message) {
8+
super(message);
9+
}
10+
11+
public JedisBusyException(final Throwable cause) {
12+
super(cause);
13+
}
14+
15+
public JedisBusyException(final String message, final Throwable cause) {
16+
super(message, cause);
17+
}
18+
19+
}

src/test/java/redis/clients/jedis/tests/ProtocolTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.Test;
1414

1515
import redis.clients.jedis.Protocol;
16+
import redis.clients.jedis.exceptions.JedisBusyException;
1617
import redis.clients.util.RedisInputStream;
1718
import redis.clients.util.RedisOutputStream;
1819
import redis.clients.util.SafeEncoder;
@@ -119,4 +120,17 @@ public void nullMultiBulkReply() {
119120
List<String> response = (List<String>) Protocol.read(new RedisInputStream(is));
120121
assertNull(response);
121122
}
122-
}
123+
124+
@Test
125+
public void busyReply() {
126+
final String busyMessage = "BUSY Redis is busy running a script.";
127+
final InputStream is = new ByteArrayInputStream(('-' + busyMessage + "\r\n").getBytes());
128+
try {
129+
Protocol.read(new RedisInputStream(is));
130+
} catch (final JedisBusyException e) {
131+
assertEquals(busyMessage, e.getMessage());
132+
return;
133+
}
134+
fail("Expected a JedisBusyException to be thrown.");
135+
}
136+
}

0 commit comments

Comments
 (0)