Skip to content

Commit

Permalink
Adopt variadic EXISTS and DEBUG HTSTATS #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jul 15, 2015
1 parent 41ca121 commit 6ccfc22
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 63 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public void debugOom() {
dispatch(commandBuilder.debugOom());
}

@Override
public RedisFuture<String> debugHtstats(int db) {
return dispatch(commandBuilder.debugHtstats(db));
}

@Override
public RedisFuture<Long> decr(K key) {
return dispatch(commandBuilder.decr(key));
Expand Down Expand Up @@ -303,6 +308,11 @@ public RedisFuture<Boolean> exists(K key) {
return dispatch(commandBuilder.exists(key));
}

@Override
public RedisFuture<Long> exists(K... keys) {
return dispatch(commandBuilder.exists(keys));
}

@Override
public RedisFuture<Boolean> expire(K key, long seconds) {
return dispatch(commandBuilder.expire(key, seconds));
Expand Down
67 changes: 14 additions & 53 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
package com.lambdaworks.redis;

import static com.lambdaworks.redis.protocol.CommandKeyword.ADDSLOTS;
import static com.lambdaworks.redis.protocol.CommandKeyword.AFTER;
import static com.lambdaworks.redis.protocol.CommandKeyword.AND;
import static com.lambdaworks.redis.protocol.CommandKeyword.BEFORE;
import static com.lambdaworks.redis.protocol.CommandKeyword.CHANNELS;
import static com.lambdaworks.redis.protocol.CommandKeyword.COUNT;
import static com.lambdaworks.redis.protocol.CommandKeyword.DELSLOTS;
import static com.lambdaworks.redis.protocol.CommandKeyword.ENCODING;
import static com.lambdaworks.redis.protocol.CommandKeyword.FAILOVER;
import static com.lambdaworks.redis.protocol.CommandKeyword.FLUSH;
import static com.lambdaworks.redis.protocol.CommandKeyword.FLUSHSLOTS;
import static com.lambdaworks.redis.protocol.CommandKeyword.FORCE;
import static com.lambdaworks.redis.protocol.CommandKeyword.FORGET;
import static com.lambdaworks.redis.protocol.CommandKeyword.GETKEYSINSLOT;
import static com.lambdaworks.redis.protocol.CommandKeyword.GETNAME;
import static com.lambdaworks.redis.protocol.CommandKeyword.HARD;
import static com.lambdaworks.redis.protocol.CommandKeyword.IDLETIME;
import static com.lambdaworks.redis.protocol.CommandKeyword.IMPORTING;
import static com.lambdaworks.redis.protocol.CommandKeyword.KILL;
import static com.lambdaworks.redis.protocol.CommandKeyword.LEN;
import static com.lambdaworks.redis.protocol.CommandKeyword.LIMIT;
import static com.lambdaworks.redis.protocol.CommandKeyword.LIST;
import static com.lambdaworks.redis.protocol.CommandKeyword.LOAD;
import static com.lambdaworks.redis.protocol.CommandKeyword.MEET;
import static com.lambdaworks.redis.protocol.CommandKeyword.MIGRATING;
import static com.lambdaworks.redis.protocol.CommandKeyword.NO;
import static com.lambdaworks.redis.protocol.CommandKeyword.NODE;
import static com.lambdaworks.redis.protocol.CommandKeyword.NODES;
import static com.lambdaworks.redis.protocol.CommandKeyword.NOSAVE;
import static com.lambdaworks.redis.protocol.CommandKeyword.NOT;
import static com.lambdaworks.redis.protocol.CommandKeyword.NUMPAT;
import static com.lambdaworks.redis.protocol.CommandKeyword.NUMSUB;
import static com.lambdaworks.redis.protocol.CommandKeyword.ONE;
import static com.lambdaworks.redis.protocol.CommandKeyword.OR;
import static com.lambdaworks.redis.protocol.CommandKeyword.PAUSE;
import static com.lambdaworks.redis.protocol.CommandKeyword.REFCOUNT;
import static com.lambdaworks.redis.protocol.CommandKeyword.REPLICATE;
import static com.lambdaworks.redis.protocol.CommandKeyword.RESET;
import static com.lambdaworks.redis.protocol.CommandKeyword.RESETSTAT;
import static com.lambdaworks.redis.protocol.CommandKeyword.REWRITE;
import static com.lambdaworks.redis.protocol.CommandKeyword.SEGFAULT;
import static com.lambdaworks.redis.protocol.CommandKeyword.SETNAME;
import static com.lambdaworks.redis.protocol.CommandKeyword.SETSLOT;
import static com.lambdaworks.redis.protocol.CommandKeyword.SLAVES;
import static com.lambdaworks.redis.protocol.CommandKeyword.SLOTS;
import static com.lambdaworks.redis.protocol.CommandKeyword.SOFT;
import static com.lambdaworks.redis.protocol.CommandKeyword.WITHSCORES;
import static com.lambdaworks.redis.protocol.CommandKeyword.XOR;
import static com.lambdaworks.redis.protocol.CommandKeyword.*;
import static com.lambdaworks.redis.protocol.CommandType.*;

import java.util.Date;
Expand Down Expand Up @@ -105,9 +58,9 @@
*/
class RedisCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {

private static final String MUST_NOT_CONTAIN_NULL_ELEMENTS = "must not contain null elements";
private static final String MUST_NOT_BE_EMPTY = "must not be empty";
private static final String MUST_NOT_BE_NULL = "must not be null";
static final String MUST_NOT_CONTAIN_NULL_ELEMENTS = "must not contain null elements";
static final String MUST_NOT_BE_EMPTY = "must not be empty";
static final String MUST_NOT_BE_NULL = "must not be null";

public RedisCommandBuilder(RedisCodec<K, V> codec) {
super(codec);
Expand Down Expand Up @@ -300,8 +253,12 @@ public Command<K, V, Void> debugSegfault() {
}

public Command<K, V, Void> debugOom() {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add("OOM");
return createCommand(DEBUG, null, args);
return createCommand(DEBUG, null, new CommandArgs<K, V>(codec).add("OOM"));
}

public Command<K, V, String> debugHtstats(int db) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(HTSTATS).add(db);
return createCommand(DEBUG, new StatusOutput<K, V>(codec), args);
}

public Command<K, V, Long> decr(K key) {
Expand Down Expand Up @@ -374,6 +331,10 @@ public Command<K, V, Boolean> exists(K key) {
return createCommand(EXISTS, new BooleanOutput<K, V>(codec), key);
}

public Command<K, V, Long> exists(K... keys) {
return createCommand(EXISTS, new IntegerOutput<K, V>(codec), new CommandArgs<K, V>(codec).addKeys(keys));
}

public Command<K, V, Boolean> expire(K key, long seconds) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(seconds);
return createCommand(EXPIRE, new BooleanOutput<K, V>(codec), args);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/lambdaworks/redis/RedisKeysAsyncConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ public interface RedisKeysAsyncConnection<K, V> {
* @return RedisFuture&lt;Boolean&gt; integer-reply specifically:
*
* {@literal true} if the key exists. {@literal false} if the key does not exist.
* @deprecated Use {@link #exists(Object[])} instead
*/
@Deprecated
RedisFuture<Boolean> exists(K key);

/**
* Determine how many keys exist.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
*/
RedisFuture<Long> exists(K... keys);

/**
* Set a key's time to live in seconds.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/lambdaworks/redis/RedisKeysConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ public interface RedisKeysConnection<K, V> {
* @return Boolean integer-reply specifically:
*
* {@literal true} if the key exists. {@literal false} if the key does not exist.
* @deprecated Use {@link #exists(Object[])} instead
*/
@Deprecated
Boolean exists(K key);

/**
* Determine how many keys exist.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
*/
Long exists(K... keys);

/**
* Set a key's time to live in seconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ public interface RedisServerAsyncConnection<K, V> {
*/
void debugOom();

/**
* Get debugging information about the internal hash-table state.
*
* @param db the database number
* @return String simple-string-reply
*/
RedisFuture<String> debugHtstats(int db);

/**
* Remove all keys from all databases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public interface RedisServerConnection<K, V> {
*/
void debugOom();

/**
* Get debugging information about the internal hash-table state.
*
* @param db the database number
* @return String simple-string-reply
*/
String debugHtstats(int db);

/**
* Remove all keys from all databases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Will Glozer
*/
public enum CommandKeyword implements ProtocolKeyword {
ADDR, ADDSLOTS, AFTER, AGGREGATE, ALPHA, AND, ASC, BEFORE, BY, CHANNELS, COUNT, DELSLOTS, DESC, SOFT, HARD, ENCODING,
ADDR, ADDSLOTS, AFTER, AGGREGATE, ALPHA, AND, ASC, BEFORE, BY, CHANNELS, COUNT, DELSLOTS, DESC, SOFT, HARD, HTSTATS, ENCODING,

FAILOVER, FORGET, FLUSH, FORCE, FLUSHSLOTS, GETNAME, GETKEYSINSLOT, ID, IDLETIME, KILL, LEN, LIMIT, LIST, LOAD, MATCH,

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/lambdaworks/redis/KeyCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public void exists() throws Exception {
assertThat(redis.exists(key)).isTrue();
}

@Test
public void existsVariadic() throws Exception {
assertThat(redis.exists(key, "key2", "key3")).isEqualTo(0);
redis.set(key, value);
redis.set("key2", value);
assertThat(redis.exists(key, "key2", "key3")).isEqualTo(2);
}

@Test
public void expire() throws Exception {
assertThat(redis.expire(key, 10)).isFalse();
Expand Down
22 changes: 13 additions & 9 deletions src/test/java/com/lambdaworks/redis/ServerCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@

package com.lambdaworks.redis;

import static com.google.code.tempusfugit.temporal.Duration.seconds;
import static com.google.code.tempusfugit.temporal.Timeout.timeout;
import static com.lambdaworks.redis.TestSettings.host;
import static com.lambdaworks.redis.TestSettings.port;
import static com.google.code.tempusfugit.temporal.Duration.*;
import static com.google.code.tempusfugit.temporal.Timeout.*;
import static com.lambdaworks.redis.TestSettings.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.FixMethodOrder;
import org.junit.Test;

import com.google.code.tempusfugit.temporal.Condition;
import com.google.code.tempusfugit.temporal.WaitFor;
import com.lambdaworks.redis.models.command.CommandDetail;
import com.lambdaworks.redis.models.command.CommandDetailParser;
import com.lambdaworks.redis.models.role.RedisInstance;
import com.lambdaworks.redis.models.role.RoleParser;
import com.lambdaworks.redis.protocol.CommandType;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
Expand Down Expand Up @@ -193,6 +190,13 @@ public boolean isSatisfied() {
assertThat(connection.isOpen()).isFalse();
}

@Test
public void debugHtstats() throws Exception {
redis.set(key, value);
String result = redis.debugHtstats(0);
assertThat(result).contains("table size");
}

@Test
public void flushall() throws Exception {
redis.set(key, value);
Expand Down

0 comments on commit 6ccfc22

Please sign in to comment.