Slowlog commands. The unit test is failing.
This commit is contained in:
@@ -7,6 +7,8 @@ import static redis.clients.jedis.Protocol.Keyword.NO;
|
||||
import static redis.clients.jedis.Protocol.Keyword.ONE;
|
||||
import static redis.clients.jedis.Protocol.Keyword.STORE;
|
||||
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
|
||||
import static redis.clients.jedis.Protocol.Keyword.RESET;
|
||||
import static redis.clients.jedis.Protocol.Keyword.LEN;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -718,4 +720,20 @@ public class BinaryClient extends Connection {
|
||||
db = 0;
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
public void slowlogGet() {
|
||||
sendCommand(SLOWLOG, Keyword.GET.raw);
|
||||
}
|
||||
|
||||
public void slowlogGet(long entries) {
|
||||
sendCommand(SLOWLOG, Keyword.GET.raw, toByteArray(entries));
|
||||
}
|
||||
|
||||
public void slowlogReset() {
|
||||
sendCommand(SLOWLOG, RESET.raw);
|
||||
}
|
||||
|
||||
public void slowlogLen() {
|
||||
sendCommand(SLOWLOG, LEN.raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3006,4 +3006,23 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
public Long getDB() {
|
||||
return client.getDB();
|
||||
}
|
||||
|
||||
public void slowlogReset() {
|
||||
client.slowlogReset();
|
||||
}
|
||||
|
||||
public long slowlogLen() {
|
||||
client.slowlogLen();
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public List<byte[]> slowlogGetBinary() {
|
||||
client.slowlogGet();
|
||||
return client.getBinaryMultiBulkReply();
|
||||
}
|
||||
|
||||
public List<byte[]> slowlogGetBinary(long entries) {
|
||||
client.slowlogGet(entries);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,4 +154,5 @@ public interface BinaryJedisCommands {
|
||||
Long zremrangeByScore(byte[] key, double start, double end);
|
||||
|
||||
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
public Jedis(final String host) {
|
||||
@@ -2688,5 +2689,15 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
public String configSet(final String parameter, final String value) {
|
||||
client.configSet(parameter, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Slowlog> slowlogGet() {
|
||||
client.slowlogGet();
|
||||
return Slowlog.from(client.getObjectMultiBulkReply());
|
||||
}
|
||||
|
||||
public List<Slowlog> slowlogGet(long entries) {
|
||||
client.slowlogGet(entries);
|
||||
return Slowlog.from(client.getObjectMultiBulkReply());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
/**
|
||||
* Common interface for sharded and non-sharded Jedis
|
||||
*/
|
||||
@@ -160,4 +162,5 @@ public interface JedisCommands {
|
||||
|
||||
Long linsert(String key, Client.LIST_POSITION where, String pivot,
|
||||
String value);
|
||||
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public final class Protocol {
|
||||
}
|
||||
|
||||
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;
|
||||
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, SLOWLOG;
|
||||
|
||||
public final byte[] raw;
|
||||
|
||||
@@ -150,7 +150,7 @@ public final class Protocol {
|
||||
}
|
||||
|
||||
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;
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LEN, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET;
|
||||
public final byte[] raw;
|
||||
|
||||
Keyword() {
|
||||
|
||||
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> list = (List<Object>)obj;
|
||||
logs.add(new Slowlog(list));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public class SlowlogCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void slowlog() {
|
||||
//do something
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
List<Slowlog> reducedLog = jedis.slowlogGet(1);
|
||||
assertEquals(1, reducedLog.size());
|
||||
|
||||
Slowlog log = reducedLog.get(0);
|
||||
assertTrue(log.getId() > 0);
|
||||
assertTrue(log.getTimeStamp() > 0);
|
||||
assertTrue(log.getExecutionTime() > 0);
|
||||
assertNotNull(log.getArgs());
|
||||
|
||||
List<byte[]> breducedLog = jedis.slowlogGetBinary(1);
|
||||
assertEquals(1, breducedLog.size());
|
||||
|
||||
List<Slowlog> log1 = jedis.slowlogGet();
|
||||
List<byte[]> blog1 = jedis.slowlogGetBinary();
|
||||
|
||||
assertNotNull(log1);
|
||||
assertNotNull(blog1);
|
||||
|
||||
long len1 = jedis.slowlogLen();
|
||||
|
||||
jedis.slowlogReset();
|
||||
|
||||
List<Slowlog> log2 = jedis.slowlogGet();
|
||||
List<byte[]> blog2 = jedis.slowlogGetBinary();
|
||||
long len2 = jedis.slowlogLen();
|
||||
|
||||
assertTrue(len1 > len2);
|
||||
assertTrue(log1.size() > log2.size());
|
||||
assertTrue(blog1.size() > blog2.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user