Object commands are supported
This commit is contained in:
@@ -6,6 +6,9 @@ import static redis.clients.jedis.Protocol.Keyword.LIMIT;
|
|||||||
import static redis.clients.jedis.Protocol.Keyword.NO;
|
import static redis.clients.jedis.Protocol.Keyword.NO;
|
||||||
import static redis.clients.jedis.Protocol.Keyword.ONE;
|
import static redis.clients.jedis.Protocol.Keyword.ONE;
|
||||||
import static redis.clients.jedis.Protocol.Keyword.STORE;
|
import static redis.clients.jedis.Protocol.Keyword.STORE;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.REFCOUNT;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.ENCODING;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.IDLETIME;
|
||||||
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
|
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -718,4 +721,16 @@ public class BinaryClient extends Connection {
|
|||||||
db = 0;
|
db = 0;
|
||||||
super.disconnect();
|
super.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void objectRefcount(byte[] key) {
|
||||||
|
sendCommand(OBJECT, REFCOUNT.raw, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectIdletime(byte[] key) {
|
||||||
|
sendCommand(OBJECT, IDLETIME.raw, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectEncoding(byte[] key) {
|
||||||
|
sendCommand(OBJECT, ENCODING.raw, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3006,4 +3006,19 @@ public class BinaryJedis implements BinaryJedisCommands {
|
|||||||
public Long getDB() {
|
public Long getDB() {
|
||||||
return client.getDB();
|
return client.getDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long objectRefcount(byte[] key) {
|
||||||
|
client.objectRefcount(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] objectEncoding(byte[] key) {
|
||||||
|
client.objectEncoding(key);
|
||||||
|
return client.getBinaryBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long objectIdletime(byte[] key) {
|
||||||
|
client.objectIdletime(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,4 +154,10 @@ public interface BinaryJedisCommands {
|
|||||||
Long zremrangeByScore(byte[] key, double start, double end);
|
Long zremrangeByScore(byte[] key, double start, double end);
|
||||||
|
|
||||||
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
|
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
|
||||||
|
|
||||||
|
Long objectRefcount(byte[] key);
|
||||||
|
|
||||||
|
Long objectIdletime(byte[] key);
|
||||||
|
|
||||||
|
byte[] objectEncoding(byte[] key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -407,4 +407,19 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
|||||||
pipeline.setShardedJedis(this);
|
pipeline.setShardedJedis(this);
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long objectRefcount(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.objectRefcount(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] objectEncoding(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.objectEncoding(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long objectIdletime(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.objectIdletime(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -595,4 +595,16 @@ public class Client extends BinaryClient implements Commands {
|
|||||||
public void configGet(String pattern) {
|
public void configGet(String pattern) {
|
||||||
configGet(SafeEncoder.encode(pattern));
|
configGet(SafeEncoder.encode(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void objectRefcount(String key) {
|
||||||
|
objectRefcount(SafeEncoder.encode(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectIdletime(String key) {
|
||||||
|
objectIdletime(SafeEncoder.encode(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectEncoding(String key) {
|
||||||
|
objectEncoding(SafeEncoder.encode(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package redis.clients.jedis;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
public interface Commands {
|
public interface Commands {
|
||||||
|
|
||||||
@@ -259,4 +260,10 @@ public interface Commands {
|
|||||||
public void exec();
|
public void exec();
|
||||||
|
|
||||||
public void discard();
|
public void discard();
|
||||||
|
|
||||||
|
public void objectRefcount(String key);
|
||||||
|
|
||||||
|
public void objectIdletime(String key);
|
||||||
|
|
||||||
|
public void objectEncoding(String key);
|
||||||
}
|
}
|
||||||
@@ -2689,4 +2689,19 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
|||||||
client.configSet(parameter, value);
|
client.configSet(parameter, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long objectRefcount(String string) {
|
||||||
|
client.objectRefcount(string);
|
||||||
|
return client.getIntegerReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String objectEncoding(String string) {
|
||||||
|
client.objectEncoding(string);
|
||||||
|
return client.getBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long objectIdletime(String string) {
|
||||||
|
client.objectIdletime(string);
|
||||||
|
return client.getIntegerReply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public final class Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum Command {
|
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, OBJECT;
|
||||||
|
|
||||||
public final byte[] raw;
|
public final byte[] raw;
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ public final class Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum Keyword {
|
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, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, REFCOUNT, ENCODING, IDLETIME;
|
||||||
public final byte[] raw;
|
public final byte[] raw;
|
||||||
|
|
||||||
Keyword() {
|
Keyword() {
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
|
public class ObjectCommandsTest extends JedisCommandTestBase {
|
||||||
|
|
||||||
|
private String key = "key";
|
||||||
|
private byte[] binaryKey = SafeEncoder.encode(key);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void objectRefcount() {
|
||||||
|
jedis.set(key, "test");
|
||||||
|
Long refcount = jedis.objectRefcount(key);
|
||||||
|
assertEquals(new Long(1), refcount);
|
||||||
|
|
||||||
|
//Binary
|
||||||
|
refcount = jedis.objectRefcount(binaryKey);
|
||||||
|
assertEquals(new Long(1), refcount);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void objectEncoding() {
|
||||||
|
jedis.set(key, "test");
|
||||||
|
String encoding = jedis.objectEncoding(key);
|
||||||
|
assertEquals("raw", encoding);
|
||||||
|
|
||||||
|
//Binary
|
||||||
|
encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey));
|
||||||
|
assertEquals("raw", encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void objectIdletime() throws InterruptedException {
|
||||||
|
jedis.set(key, "test");
|
||||||
|
|
||||||
|
//Wait a little bit more than 10 seconds so the idle time is 10 seconds.
|
||||||
|
Thread.sleep(10001);
|
||||||
|
Long time = jedis.objectIdletime(key);
|
||||||
|
assertEquals(new Long(10), time);
|
||||||
|
|
||||||
|
//Binary
|
||||||
|
time = jedis.objectIdletime(binaryKey);
|
||||||
|
assertEquals(new Long(10), time);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user