add bitset and bitget
This commit is contained in:
@@ -636,4 +636,12 @@ public class BinaryClient extends Connection {
|
||||
public void configResetStat() {
|
||||
sendCommand(CONFIG, Keyword.RESETSTAT.name());
|
||||
}
|
||||
|
||||
public void setbit(byte[] key, int offset, byte[] value) {
|
||||
sendCommand(SETBIT, key, toByteArray(offset), value);
|
||||
}
|
||||
|
||||
public void getbit(byte[] key, int offset) {
|
||||
sendCommand(GETBIT, key, toByteArray(offset));
|
||||
}
|
||||
}
|
||||
@@ -2901,4 +2901,28 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or clears the bit at offset in the string value stored at key
|
||||
*
|
||||
* @param key
|
||||
* @param offset
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long setbit(byte[] key, int offset, byte[] value) {
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit value at offset in the string value stored at key
|
||||
*
|
||||
* @param key
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
public Long getbit(byte[] key, int offset) {
|
||||
client.getbit(key, offset);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
}
|
||||
@@ -506,4 +506,12 @@ public class Client extends BinaryClient implements Commands {
|
||||
brpoplpush(SafeEncoder.encode(source), SafeEncoder.encode(destination),
|
||||
timeout);
|
||||
}
|
||||
|
||||
public void setbit(final String key, final int offset, final String value) {
|
||||
setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
public void getbit(String key, int offset) {
|
||||
getbit(SafeEncoder.encode(key), offset);
|
||||
}
|
||||
}
|
||||
@@ -2595,4 +2595,29 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or clears the bit at offset in the string value stored at key
|
||||
*
|
||||
* @param key
|
||||
* @param offset
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long setbit(String key, int offset, String value) {
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit value at offset in the string value stored at key
|
||||
*
|
||||
* @param key
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
public Long getbit(String key, int offset) {
|
||||
client.getbit(key, offset);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,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, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH;
|
||||
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, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT;
|
||||
|
||||
public final byte[] raw;
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BitCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void setAndgetbit() {
|
||||
long bit = jedis.setbit("foo", 0, "1");
|
||||
assertEquals(0, bit);
|
||||
|
||||
bit = jedis.getbit("foo", 0);
|
||||
assertEquals(1, bit);
|
||||
|
||||
long bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes());
|
||||
assertEquals(0, bbit);
|
||||
|
||||
bbit = jedis.getbit("bfoo".getBytes(), 0);
|
||||
assertEquals(1, bbit);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user