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 3e98dc5 commit 142eb79
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,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 @@ -292,6 +297,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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ public Observable<Void> debugOom() {
return createObservable(commandBuilder::debugOom);
}

@Override
public Observable<String> debugHtstats(int db) {
return createObservable(() -> commandBuilder.debugHtstats(db));
}

@Override
public Observable<Long> decr(K key) {
return createObservable(() -> commandBuilder.decr(key));
Expand Down Expand Up @@ -283,14 +288,18 @@ public Observable<Boolean> exists(K key) {
return createObservable(() -> commandBuilder.exists(key));
}

@Override
public Observable<Long> exists(K... keys) {
return createObservable(() -> commandBuilder.exists(keys));
}

@Override
public Observable<Boolean> expire(K key, long seconds) {
return createObservable(() -> commandBuilder.expire(key, seconds));
}

@Override
public Observable<Boolean> expireat(K key, Date timestamp) {

return expireat(key, timestamp.getTime() / 1000);
}

Expand Down
58 changes: 10 additions & 48 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
package com.lambdaworks.redis;

import static com.lambdaworks.redis.LettuceStrings.string;
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 @@ -304,6 +257,11 @@ public Command<K, V, Void> debugOom() {
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) {
return createCommand(DECR, new IntegerOutput<K, V>(codec), key);
}
Expand Down Expand Up @@ -379,6 +337,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
12 changes: 10 additions & 2 deletions src/main/java/com/lambdaworks/redis/RedisKeysAsyncConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.Date;
import java.util.List;

import com.lambdaworks.redis.api.async.RedisKeyAsyncCommands;
import com.lambdaworks.redis.api.sync.RedisKeyCommands;
import com.lambdaworks.redis.output.KeyStreamingChannel;
import com.lambdaworks.redis.output.ValueStreamingChannel;

Expand Down Expand Up @@ -42,9 +40,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
11 changes: 10 additions & 1 deletion src/main/java/com/lambdaworks/redis/RedisKeysConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Date;
import java.util.List;

import com.lambdaworks.redis.api.sync.RedisKeyCommands;
import com.lambdaworks.redis.output.KeyStreamingChannel;
import com.lambdaworks.redis.output.ValueStreamingChannel;

Expand Down Expand Up @@ -41,9 +40,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 @@ -166,6 +166,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 @@ -165,6 +165,14 @@ public interface RedisServerConnection<K, V> extends RedisServerCommands<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 @@ -48,6 +48,14 @@ public interface RedisKeyAsyncCommands<K, V> {
*/
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ public interface RedisServerAsyncCommands<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 @@ -48,6 +48,14 @@ public interface RedisKeyReactiveCommands<K, V> {
*/
Observable<Boolean> exists(K key);

/**
* Determine how many keys exist.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
*/
Observable<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 @@ -167,6 +167,14 @@ public interface RedisServerReactiveCommands<K, V> {
*/
Observable<Void> debugOom();

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

/**
* Remove all keys from all databases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public interface RedisKeyCommands<K, V> {
*/
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 @@ -166,6 +166,14 @@ public interface RedisServerCommands<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 @@ -48,6 +48,14 @@ public interface NodeSelectionKeyAsyncCommands<K, V> {
*/
AsyncExecutions<Boolean> exists(K key);

/**
* Determine how many keys exist.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
*/
AsyncExecutions<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 @@ -155,6 +155,14 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
*/
AsyncExecutions<String> debugObject(K key);

/**
* Get debugging information about the internal hash-table state.
*
* @param db the database number
* @return String simple-string-reply
*/
AsyncExecutions<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
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ public interface RedisKeyCommands<K, V> {
byte[] dump(K key);

/**
* Determine if a key exists.
*
* @param key the key
* @return Boolean integer-reply specifically:
*
* {@literal true} if the key exists. {@literal false} if the key does not exist.
* Determine how many keys exist.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
*/
Boolean exists(K key);
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 @@ -165,6 +165,14 @@ public interface RedisServerCommands<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
Loading

0 comments on commit 142eb79

Please sign in to comment.