Skip to content

Commit

Permalink
Refactor command enum so we can extend commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Apr 27, 2015
1 parent a52902b commit f2a1036
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private Protocol() {
// this prevent the class from instantiation
}

public static void sendCommand(final RedisOutputStream os, final Command command,
public static void sendCommand(final RedisOutputStream os, final ProtocolCommand command,
final byte[]... args) {
sendCommand(os, command.raw, args);
sendCommand(os, command.getRaw(), args);
}

private static void sendCommand(final RedisOutputStream os, final byte[] command,
Expand Down Expand Up @@ -212,14 +212,19 @@ public static final byte[] toByteArray(final double value) {
return SafeEncoder.encode(String.valueOf(value));
}

public static enum Command {
public static enum Command implements ProtocolCommand {
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, ZLEXCOUNT, ZRANGEBYLEX, ZREVRANGEBYLEX, ZREMRANGEBYLEX, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE;

public final byte[] raw;
private final byte[] raw;

Command() {
raw = SafeEncoder.encode(this.name());
}

@Override
public byte[] getRaw() {
return raw;
}
}

public static enum Keyword {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/ProtocolCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package redis.clients.jedis;

public interface ProtocolCommand {

public byte[] getRaw();

}

0 comments on commit f2a1036

Please sign in to comment.