add missing command to Transaction, BinaryTransaction and Pipeline

This commit is contained in:
Jonathan Leibiusky
2011-12-23 12:31:32 -03:00
parent 6f4a32d2a1
commit 72ca494362
9 changed files with 235 additions and 44 deletions

View File

@@ -643,12 +643,12 @@ public class BinaryClient extends Connection {
sendCommand(SLAVEOF, NO.raw, ONE.raw);
}
public void configGet(final String pattern) {
sendCommand(CONFIG, Keyword.GET.name(), pattern);
public void configGet(final byte[] pattern) {
sendCommand(CONFIG, Keyword.GET.raw, pattern);
}
public void configSet(final String parameter, final String value) {
sendCommand(CONFIG, Keyword.SET.name(), parameter, value);
public void configSet(final byte[] parameter, final byte[] value) {
sendCommand(CONFIG, Keyword.SET.raw, parameter, value);
}
public void strlen(final byte[] key) {

View File

@@ -2822,9 +2822,9 @@ public class BinaryJedis implements BinaryJedisCommands {
* @param pattern
* @return Bulk reply.
*/
public List<String> configGet(final String pattern) {
public List<byte[]> configGet(final byte[] pattern) {
client.configGet(pattern);
return client.getMultiBulkReply();
return client.getBinaryMultiBulkReply();
}
/**
@@ -2871,9 +2871,9 @@ public class BinaryJedis implements BinaryJedisCommands {
* @param value
* @return Status code reply
*/
public String configSet(final String parameter, final String value) {
public byte[] configSet(final byte[] parameter, final byte[] value) {
client.configSet(parameter, value);
return client.getStatusCodeReply();
return client.getBinaryBulkReply();
}
public boolean isConnected() {
@@ -2959,9 +2959,9 @@ public class BinaryJedis implements BinaryJedisCommands {
* @param value
* @return
*/
public Long setbit(byte[] key, long offset, byte[] value) {
public Boolean setbit(byte[] key, long offset, byte[] value) {
client.setbit(key, offset, value);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**
@@ -2971,12 +2971,12 @@ public class BinaryJedis implements BinaryJedisCommands {
* @param offset
* @return
*/
public Long getbit(byte[] key, long offset) {
public Boolean getbit(byte[] key, long offset) {
client.getbit(key, offset);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
public long setrange(byte[] key, long offset, byte[] value) {
public Long setrange(byte[] key, long offset, byte[] value) {
client.setrange(key, offset, value);
return client.getIntegerReply();
}

View File

@@ -568,4 +568,84 @@ public class BinaryTransaction extends Queable {
client.select(index);
return getResponse(BuilderFactory.STRING);
}
}
public Response<String> flushDB() {
client.flushDB();
return getResponse(BuilderFactory.STRING);
}
public Response<String> flushAll() {
client.flushAll();
return getResponse(BuilderFactory.STRING);
}
public Response<String> save() {
client.save();
return getResponse(BuilderFactory.STRING);
}
public Response<String> info() {
client.info();
return getResponse(BuilderFactory.STRING);
}
public Response<Long> lastsave() {
client.lastsave();
return getResponse(BuilderFactory.LONG);
}
public Response<Long> dbSize() {
client.dbSize();
return getResponse(BuilderFactory.LONG);
}
public Response<List<byte[]>> configGet(final byte[] pattern) {
client.configGet(pattern);
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
}
public Response<byte[]> configSet(final byte[] parameter, final byte[] value) {
client.configSet(parameter, value);
return getResponse(BuilderFactory.BYTE_ARRAY);
}
public Response<String> configResetStat() {
client.configResetStat();
return getResponse(BuilderFactory.STRING);
}
public Response<String> shutdown() {
client.shutdown();
return getResponse(BuilderFactory.STRING);
}
public Response<Boolean> getbit(final byte[] key, final long offset) {
client.getbit(key, offset);
return getResponse(BuilderFactory.BOOLEAN);
}
public Response<Boolean> setbit(final byte[] key, final long offset, final byte[] value) {
client.setbit(key, offset, value);
return getResponse(BuilderFactory.BOOLEAN);
}
public Response<String> ping() {
client.ping();
return getResponse(BuilderFactory.STRING);
}
public Response<Long> setrange(byte[] key, long offset, byte[] value) {
client.setrange(key, offset, value);
return getResponse(BuilderFactory.LONG);
}
public Response<String> randomKey() {
client.randomKey();
return getResponse(BuilderFactory.STRING);
}
public Response<Long> publish(byte[] channel, byte[] message) {
client.publish(channel, message);
return getResponse(BuilderFactory.LONG);
}
}

View File

@@ -587,4 +587,12 @@ public class Client extends BinaryClient implements Commands {
}
subscribe(cs);
}
public void configSet(String parameter, String value) {
configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value));
}
public void configGet(String pattern) {
configGet(SafeEncoder.encode(pattern));
}
}

View File

@@ -226,18 +226,6 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return client.getIntegerReply();
}
/**
* Return the number of keys in the currently selected database.
*
* @return Integer reply
*/
public Long dbSize() {
checkIsInMulti();
client.dbSize();
return client.getIntegerReply();
}
/**
* Set a timeout on the specified key. After the timeout the key will be
* automatically deleted by the server. A key with an associated timeout is
@@ -2595,7 +2583,7 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @param value
* @return
*/
public boolean setbit(String key, long offset, boolean value) {
public Boolean setbit(String key, long offset, boolean value) {
client.setbit(key, offset, value);
return client.getIntegerReply() == 1;
}
@@ -2607,12 +2595,12 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @param offset
* @return
*/
public boolean getbit(String key, long offset) {
public Boolean getbit(String key, long offset) {
client.getbit(key, offset);
return client.getIntegerReply() == 1;
}
public long setrange(String key, long offset, String value) {
public Long setrange(String key, long offset, String value) {
client.setrange(key, offset, value);
return client.getIntegerReply();
}
@@ -2621,4 +2609,84 @@ public class Jedis extends BinaryJedis implements JedisCommands {
client.getrange(key, startOffset, endOffset);
return client.getBulkReply();
}
/**
* Retrieve the configuration of a running Redis server. Not all the
* configuration parameters are supported.
* <p>
* CONFIG GET returns the current configuration parameters. This sub command
* only accepts a single argument, that is glob style pattern. All the
* configuration parameters matching this parameter are reported as a list
* of key-value pairs.
* <p>
* <b>Example:</b>
*
* <pre>
* $ redis-cli config get '*'
* 1. "dbfilename"
* 2. "dump.rdb"
* 3. "requirepass"
* 4. (nil)
* 5. "masterauth"
* 6. (nil)
* 7. "maxmemory"
* 8. "0\n"
* 9. "appendfsync"
* 10. "everysec"
* 11. "save"
* 12. "3600 1 300 100 60 10000"
*
* $ redis-cli config get 'm*'
* 1. "masterauth"
* 2. (nil)
* 3. "maxmemory"
* 4. "0\n"
* </pre>
*
* @param pattern
* @return Bulk reply.
*/
public List<String> configGet(final String pattern) {
client.configGet(pattern);
return client.getMultiBulkReply();
}
/**
* Alter the configuration of a running Redis server. Not all the
* configuration parameters are supported.
* <p>
* The list of configuration parameters supported by CONFIG SET can be
* obtained issuing a {@link #configGet(String) CONFIG GET *} command.
* <p>
* The configuration set using CONFIG SET is immediately loaded by the Redis
* server that will start acting as specified starting from the next
* command.
* <p>
*
* <b>Parameters value format</b>
* <p>
* The value of the configuration parameter is the same as the one of the
* same parameter in the Redis configuration file, with the following
* exceptions:
* <p>
* <ul>
* <li>The save paramter is a list of space-separated integers. Every pair
* of integers specify the time and number of changes limit to trigger a
* save. For instance the command CONFIG SET save "3600 10 60 10000" will
* configure the server to issue a background saving of the RDB file every
* 3600 seconds if there are at least 10 changes in the dataset, and every
* 60 seconds if there are at least 10000 changes. To completely disable
* automatic snapshots just set the parameter as an empty string.
* <li>All the integer parameters representing memory are returned and
* accepted only using bytes as unit.
* </ul>
*
* @param parameter
* @param value
* @return Status code reply
*/
public String configSet(final String parameter, final String value) {
client.configSet(parameter, value);
return client.getStatusCodeReply();
}
}

View File

@@ -22,11 +22,11 @@ public interface JedisCommands {
Long ttl(String key);
boolean setbit(String key, long offset, boolean value);
Boolean setbit(String key, long offset, boolean value);
boolean getbit(String key, long offset);
Boolean getbit(String key, long offset);
long setrange(String key, long offset, String value);
Long setrange(String key, long offset, String value);
String getrange(String key, long startOffset, long endOffset);

View File

@@ -40,11 +40,11 @@ public class Pipeline extends Queable {
List<Object> unformatted = client.getAll();
List<Object> formatted = new ArrayList<Object>();
for (Object o : unformatted) {
try{
formatted.add(generateResponse(o).get());
}catch(JedisDataException e){
formatted.add(e);
}
try {
formatted.add(generateResponse(o).get());
} catch (JedisDataException e) {
formatted.add(e);
}
}
return formatted;
}
@@ -1191,4 +1191,39 @@ public class Pipeline extends Queable {
client.publish(channel, message);
return getResponse(BuilderFactory.LONG);
}
}
public Response<String> flushDB() {
client.flushDB();
return getResponse(BuilderFactory.STRING);
}
public Response<String> flushAll() {
client.flushAll();
return getResponse(BuilderFactory.STRING);
}
public Response<String> info() {
client.info();
return getResponse(BuilderFactory.STRING);
}
public Response<Long> dbSize() {
client.dbSize();
return getResponse(BuilderFactory.LONG);
}
public Response<String> shutdown() {
client.shutdown();
return getResponse(BuilderFactory.STRING);
}
public Response<String> ping() {
client.ping();
return getResponse(BuilderFactory.STRING);
}
public Response<String> randomKey() {
client.randomKey();
return getResponse(BuilderFactory.STRING);
}
}

View File

@@ -68,17 +68,17 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.ttl(key);
}
public boolean setbit(String key, long offset, boolean value) {
public Boolean setbit(String key, long offset, boolean value) {
Jedis j = getShard(key);
return j.setbit(key, offset, value);
}
public boolean getbit(String key, long offset) {
public Boolean getbit(String key, long offset) {
Jedis j = getShard(key);
return j.getbit(key, offset);
}
public long setrange(String key, long offset, String value) {
public Long setrange(String key, long offset, String value) {
Jedis j = getShard(key);
return j.setrange(key, offset, value);
}