Skip to content

Commit

Permalink
Add support for COMMAND COUNT #9
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Aug 10, 2014
1 parent e1dfeb9 commit 4032960
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lambdaworks.redis;

import static com.google.common.base.Preconditions.*;

import java.io.Closeable;
import java.lang.reflect.Proxy;
import java.net.SocketAddress;
Expand All @@ -12,11 +14,7 @@
import com.lambdaworks.redis.pubsub.PubSubCommandHandler;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.ChannelGroupFuture;
import io.netty.channel.group.DefaultChannelGroup;
Expand Down Expand Up @@ -187,18 +185,22 @@ protected <K, V> Object syncHandler(RedisAsyncConnectionImpl<K, V> connection, C
* connection, the listener will be notified. The corresponding netty channel handler (async connection) is passed on the
* event.
*
* @param listener
* @param listener must not be {@literal null}
*/
public void addListener(RedisConnectionStateListener listener) {
checkArgument(listener != null, "RedisConnectionStateListener must not be null");
connectionEvents.addListener(listener);
}

/**
* Removes a listener.
*
* @param listener
* @param listener must not be {@literal null
*/
public void removeListener(RedisConnectionStateListener listener) {

checkArgument(listener != null, "RedisConnectionStateListener must not be null");
connectionEvents.removeListener(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.lambdaworks.redis;

import static com.lambdaworks.redis.protocol.CommandType.EXEC;
import static com.lambdaworks.redis.protocol.CommandType.*;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -14,18 +14,8 @@

import com.lambdaworks.codec.Base16;
import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.output.KeyStreamingChannel;
import com.lambdaworks.redis.output.KeyValueStreamingChannel;
import com.lambdaworks.redis.output.MultiOutput;
import com.lambdaworks.redis.output.ScoredValueStreamingChannel;
import com.lambdaworks.redis.output.ValueStreamingChannel;
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandOutput;
import com.lambdaworks.redis.protocol.CommandType;
import com.lambdaworks.redis.protocol.ConnectionWatchdog;
import com.lambdaworks.redis.protocol.RedisCommand;
import com.lambdaworks.redis.protocol.SetArgs;
import com.lambdaworks.redis.output.*;
import com.lambdaworks.redis.protocol.*;
import io.netty.channel.ChannelHandler;

/**
Expand Down Expand Up @@ -169,6 +159,11 @@ public RedisFuture<String> clientList() {
return dispatch(commandBuilder.clientList());
}

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

@Override
public RedisFuture<List<String>> configGet(String parameter) {
return dispatch(commandBuilder.configGet(parameter));
Expand Down Expand Up @@ -1459,12 +1454,12 @@ public RedisFuture<List<K>> clusterGetKeysInSlot(int slot, int count) {
return dispatch(commandBuilder.clusterGetKeysInSlot(slot, count));
}

@Override
public RedisFuture<List<Object>> clusterSlots() {
return dispatch(commandBuilder.clusterSlots());
}
@Override
public RedisFuture<List<Object>> clusterSlots() {
return dispatch(commandBuilder.clusterSlots());
}

@Override
@Override
public RedisFuture<String> clusterSetSlotNode(int slot, String nodeId) {
return dispatch(commandBuilder.clusterSetSlotNode(slot, nodeId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.output.*;
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandOutput;
import com.lambdaworks.redis.protocol.RedisCommand;
import com.lambdaworks.redis.protocol.SetArgs;
import com.lambdaworks.redis.protocol.*;

/**
*
Expand Down Expand Up @@ -133,6 +129,11 @@ public Command<K, V, String> clientList() {
return createCommand(CLIENT, new StatusOutput<K, V>(codec), args);
}

public Command<K, V, Long> commandCount() {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(COUNT);
return createCommand(COMMAND, new IntegerOutput<K, V>(codec), args);
}

public Command<K, V, String> configRewrite() {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(REWRITE);
return createCommand(CONFIG, new StatusOutput<K, V>(codec), args);
Expand Down Expand Up @@ -1401,7 +1402,8 @@ public Command<K, V, List<K>> clusterGetKeysInSlot(int slot, int count) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(GETKEYSINSLOT).add(slot).add(count);
return createCommand(CLUSTER, new KeyListOutput<K, V>(codec), args);
}
public Command<K, V, List<Object>> clusterSlots() {

public Command<K, V, List<Object>> clusterSlots() {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(SLOTS);
return createCommand(CLUSTER, new ArrayOutput<K, V>(codec), args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public interface RedisServerAsyncConnection<K, V> {
*/
RedisFuture<String> clientList();

/**
* Get total number of Redis commands.
*
* @return RedisFuture&lt;Long&gt; integer-reply of number of total commands in this Redis server.
*/
RedisFuture<Long> commandCount();

/**
* Get the value of a configuration parameter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public interface RedisServerConnection<K, V> {
*/
String clientList();

/**
* Get total number of Redis commands.
*
* @return Long integer-reply of number of total commands in this Redis server.
*/
Long commandCount();

/**
* Get the value of a configuration parameter.
*
Expand Down Expand Up @@ -235,4 +242,5 @@ public interface RedisServerConnection<K, V> {
* unix time in seconds. microseconds.
*/
List<V> time();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum CommandType {

// Server

BGREWRITEAOF, BGSAVE, CLIENT, CONFIG, DBSIZE, DEBUG, FLUSHALL, FLUSHDB, INFO, LASTSAVE, ROLE, MONITOR, SAVE, SHUTDOWN, SLAVEOF, SLOWLOG, SYNC,
BGREWRITEAOF, BGSAVE, CLIENT, COMMAND, CONFIG, DBSIZE, DEBUG, FLUSHALL, FLUSHDB, INFO, LASTSAVE, ROLE, MONITOR, SAVE, SHUTDOWN, SLAVEOF, SLOWLOG, SYNC,

// Keys

Expand Down
15 changes: 15 additions & 0 deletions lettuce/src/test/java/com/lambdaworks/redis/ScanCursorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.lambdaworks.redis;

import static org.assertj.core.api.Assertions.*;

import org.junit.Test;

public class ScanCursorTest {

@Test
public void testFactory() throws Exception {
ScanCursor scanCursor = ScanCursor.of("dummy");
assertThat(scanCursor.getCursor()).isEqualTo("dummy");
assertThat(scanCursor.isFinished()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

import java.net.InetSocketAddress;
Expand All @@ -15,11 +15,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.*;

public class SentinelCommandTest extends AbstractCommandTest {

Expand Down Expand Up @@ -82,6 +78,17 @@ public void masters() throws Exception {

}

@Test
public void sentinelConnect() throws Exception {

RedisClient client = new RedisClient(RedisURI.Builder.redis(host, port).build());
RedisSentinelAsyncConnection<String, String> connection = client.connectSentinelAsync();
assertThat(connection.ping().get()).isEqualTo("PONG");

connection.close();
client.shutdown();
}

@Test
public void getSlaveDownstate() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void clientList() throws Exception {
assertThat(redis.clientList().contains("addr=")).isTrue();
}

@Test
public void commandCount() throws Exception {
assertThat(redis.commandCount()).isGreaterThan(100);
}

@Test
public void configGet() throws Exception {
assertThat(redis.configGet("maxmemory")).isEqualTo(list("maxmemory", "0"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.lambdaworks.redis.cluster;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import org.junit.Test;
Expand Down Expand Up @@ -43,6 +43,10 @@ public void testParse() throws Exception {
RedisClusterNode p3 = result.getPartitions().get(2);

assertThat(p3.getSlaveOf()).isEqualTo("4213a8dabb94f92eb6a860f4d0729e6a25d43e0c");
assertThat(p3.toString()).contains(RedisClusterNode.class.getSimpleName());
assertThat(result.toString()).contains(Partitions.class.getSimpleName());

assertThat(result.getPartitionBySlot(Integer.MAX_VALUE)).isNull();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambdaworks.redis.support;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.enterprise.inject.Produces;

Expand All @@ -11,6 +12,7 @@
import org.junit.Test;

import com.lambdaworks.redis.AbstractCommandTest;
import com.lambdaworks.redis.RedisConnectionStateListener;
import com.lambdaworks.redis.RedisURI;

/**
Expand Down Expand Up @@ -40,6 +42,12 @@ public void testInjection() {
InjectedClient injectedClient = container.getInstance(InjectedClient.class);
assertThat(injectedClient.redisClient).isNotNull();
assertThat(injectedClient.redisClusterClient).isNotNull();

RedisConnectionStateListener mock = mock(RedisConnectionStateListener.class);

// do some interaction to force the container a creation of the repositories.
injectedClient.redisClient.addListener(mock);
injectedClient.redisClusterClient.addListener(mock);
}

@AfterClass
Expand Down

0 comments on commit 4032960

Please sign in to comment.