Skip to content

Commit 3a3b89a

Browse files
authored
Added Rawable interface (#2370)
* Added Raw interface Jedis should have a common interface to represent all commands and keywords (and, perhaps, arguments). Closest thing we currently have is `ProtocolCommand` interface. But the problem is that it contains the word COMMAND which would be misleading to use for something other than commands. One option is to rename the existing interface. But this would be a breaking change and so it can't be available before at least Jedis 4.0. Even that can be received negatively by the users who could be using the existing interface. Having a parent interface, on the other hand, does not have such issues and can be included in upcoming non-major release. I went with name `Raw`, instead of other names like `ProtocolKeyword` or `ProtocolArgument`, because it is short and fits nicely with our go to method `getRaw()`. * dedicated package I have also put it in a separate package because with growing number of classes, we'd be able to put some classes in that package. * Rawable `Raw` in now `Rawable`. Idea courtesy goes to @gkorland.
1 parent c291f17 commit 3a3b89a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.Locale;
77

8+
import redis.clients.jedis.args.Rawable;
89
import redis.clients.jedis.commands.ProtocolCommand;
910
import redis.clients.jedis.exceptions.*;
1011
import redis.clients.jedis.util.RedisInputStream;
@@ -275,7 +276,7 @@ public byte[] getRaw() {
275276
}
276277
}
277278

278-
public static enum Keyword {
279+
public static enum Keyword implements Rawable {
279280
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE,
280281
PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES,
281282
RESETSTAT, REWRITE, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME,
@@ -294,6 +295,7 @@ public static enum Keyword {
294295
raw = SafeEncoder.encode(this.name().toLowerCase(Locale.ENGLISH));
295296
}
296297

298+
@Override
297299
public byte[] getRaw() {
298300
return raw;
299301
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package redis.clients.jedis.args;
2+
3+
public interface Rawable {
4+
5+
byte[] getRaw();
6+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package redis.clients.jedis.commands;
22

3-
public interface ProtocolCommand {
4-
5-
byte[] getRaw();
3+
import redis.clients.jedis.args.Rawable;
64

5+
public interface ProtocolCommand extends Rawable {
76
}

0 commit comments

Comments
 (0)