Merge branch 'slowlog' of git://github.com/ivowiblo/jedis into slowlog
Conflicts: src/main/java/redis/clients/jedis/BinaryClient.java src/main/java/redis/clients/jedis/BinaryJedis.java src/main/java/redis/clients/jedis/Jedis.java src/main/java/redis/clients/jedis/Protocol.java
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,143 +25,141 @@ public final class Protocol {
|
||||
public static final byte COLON_BYTE = ':';
|
||||
|
||||
private Protocol() {
|
||||
// this prevent the class from instantiation
|
||||
// this prevent the class from instantiation
|
||||
}
|
||||
|
||||
public static void sendCommand(final RedisOutputStream os,
|
||||
final Command command,
|
||||
final byte[]... args) {
|
||||
sendCommand(os, command.raw, args);
|
||||
final Command command, final byte[]... args) {
|
||||
sendCommand(os, command.raw, args);
|
||||
}
|
||||
|
||||
private static void sendCommand(final RedisOutputStream os,
|
||||
final byte[] command,
|
||||
final byte[]... args) {
|
||||
try {
|
||||
os.write(ASTERISK_BYTE);
|
||||
os.writeIntCrLf(args.length + 1);
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(command.length);
|
||||
os.write(command);
|
||||
os.writeCrLf();
|
||||
final byte[] command, final byte[]... args) {
|
||||
try {
|
||||
os.write(ASTERISK_BYTE);
|
||||
os.writeIntCrLf(args.length + 1);
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(command.length);
|
||||
os.write(command);
|
||||
os.writeCrLf();
|
||||
|
||||
for (final byte[] arg : args) {
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(arg.length);
|
||||
os.write(arg);
|
||||
os.writeCrLf();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
for (final byte[] arg : args) {
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(arg.length);
|
||||
os.write(arg);
|
||||
os.writeCrLf();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processError(final RedisInputStream is) {
|
||||
String message = is.readLine();
|
||||
throw new JedisDataException(message);
|
||||
String message = is.readLine();
|
||||
throw new JedisDataException(message);
|
||||
}
|
||||
|
||||
private static Object process(final RedisInputStream is) {
|
||||
try {
|
||||
byte b = is.readByte();
|
||||
if (b == MINUS_BYTE) {
|
||||
processError(is);
|
||||
} else if (b == ASTERISK_BYTE) {
|
||||
return processMultiBulkReply(is);
|
||||
} else if (b == COLON_BYTE) {
|
||||
return processInteger(is);
|
||||
} else if (b == DOLLAR_BYTE) {
|
||||
return processBulkReply(is);
|
||||
} else if (b == PLUS_BYTE) {
|
||||
return processStatusCodeReply(is);
|
||||
} else {
|
||||
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
return null;
|
||||
try {
|
||||
byte b = is.readByte();
|
||||
if (b == MINUS_BYTE) {
|
||||
processError(is);
|
||||
} else if (b == ASTERISK_BYTE) {
|
||||
return processMultiBulkReply(is);
|
||||
} else if (b == COLON_BYTE) {
|
||||
return processInteger(is);
|
||||
} else if (b == DOLLAR_BYTE) {
|
||||
return processBulkReply(is);
|
||||
} else if (b == PLUS_BYTE) {
|
||||
return processStatusCodeReply(is);
|
||||
} else {
|
||||
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static byte[] processStatusCodeReply(final RedisInputStream is) {
|
||||
return SafeEncoder.encode(is.readLine());
|
||||
return SafeEncoder.encode(is.readLine());
|
||||
}
|
||||
|
||||
private static byte[] processBulkReply(final RedisInputStream is) {
|
||||
int len = Integer.parseInt(is.readLine());
|
||||
if (len == -1) {
|
||||
return null;
|
||||
}
|
||||
byte[] read = new byte[len];
|
||||
int offset = 0;
|
||||
try {
|
||||
while (offset < len) {
|
||||
offset += is.read(read, offset, (len - offset));
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
is.readByte();
|
||||
is.readByte();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
int len = Integer.parseInt(is.readLine());
|
||||
if (len == -1) {
|
||||
return null;
|
||||
}
|
||||
byte[] read = new byte[len];
|
||||
int offset = 0;
|
||||
try {
|
||||
while (offset < len) {
|
||||
offset += is.read(read, offset, (len - offset));
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
is.readByte();
|
||||
is.readByte();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
|
||||
return read;
|
||||
return read;
|
||||
}
|
||||
|
||||
private static Long processInteger(final RedisInputStream is) {
|
||||
String num = is.readLine();
|
||||
return Long.valueOf(num);
|
||||
String num = is.readLine();
|
||||
return Long.valueOf(num);
|
||||
}
|
||||
|
||||
private static List<Object> processMultiBulkReply(final RedisInputStream is) {
|
||||
int num = Integer.parseInt(is.readLine());
|
||||
if (num == -1) {
|
||||
return null;
|
||||
}
|
||||
List<Object> ret = new ArrayList<Object>(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
try{
|
||||
ret.add(process(is));
|
||||
}catch(JedisDataException e){
|
||||
ret.add(e);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
int num = Integer.parseInt(is.readLine());
|
||||
if (num == -1) {
|
||||
return null;
|
||||
}
|
||||
List<Object> ret = new ArrayList<Object>(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
try {
|
||||
ret.add(process(is));
|
||||
} catch (JedisDataException e) {
|
||||
ret.add(e);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Object read(final RedisInputStream is) {
|
||||
return process(is);
|
||||
return process(is);
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final int value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final long value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final double value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static enum Command {
|
||||
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, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT;
|
||||
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, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG;
|
||||
|
||||
public final byte[] raw;
|
||||
public final byte[] raw;
|
||||
|
||||
Command() {
|
||||
raw = SafeEncoder.encode(this.name());
|
||||
}
|
||||
Command() {
|
||||
raw = SafeEncoder.encode(this.name());
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Keyword {
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, FLUSH, EXISTS, LOAD, KILL;
|
||||
public final byte[] raw;
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN;
|
||||
public final byte[] raw;
|
||||
|
||||
Keyword() {
|
||||
raw = SafeEncoder.encode(this.name().toLowerCase());
|
||||
}
|
||||
Keyword() {
|
||||
raw = SafeEncoder.encode(this.name().toLowerCase());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main/java/redis/clients/util/Slowlog.java
Normal file
53
src/main/java/redis/clients/util/Slowlog.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Slowlog {
|
||||
private final long id;
|
||||
private final long timeStamp;
|
||||
private final long executionTime;
|
||||
private final List<String> args;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slowlog> from(List<Object> nestedMultiBulkReply){
|
||||
List<Slowlog> logs = new ArrayList<Slowlog>(nestedMultiBulkReply.size());
|
||||
for(Object obj : nestedMultiBulkReply){
|
||||
List<Object> properties = (List<Object>)obj;
|
||||
logs.add(new Slowlog(properties));
|
||||
}
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Slowlog(List<Object> properties) {
|
||||
super();
|
||||
this.id = (Long)properties.get(0);
|
||||
this.timeStamp = (Long)properties.get(1);
|
||||
this.executionTime = (Long)properties.get(2);
|
||||
|
||||
List<byte[]> bargs = (List<byte[]>)properties.get(3);
|
||||
this.args = new ArrayList<String>(bargs.size());
|
||||
|
||||
for(byte[] barg:bargs){
|
||||
this.args.add(SafeEncoder.encode(barg));
|
||||
}
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public long getExecutionTime() {
|
||||
return executionTime;
|
||||
}
|
||||
|
||||
public List<String> getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user