Skip to content

Commit

Permalink
ISPN-14880 RESP DBSIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant committed May 19, 2023
1 parent 0135ed6 commit e18dbcc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Expand Up @@ -16,6 +16,9 @@ The {brandname} RESP endpoint implements the following Redis commands:
| link:https://redis.io/commands/command[COMMAND]
|

| link:https://redis.io/commands/dbsize[DBSIZE]
|

| link:https://redis.io/commands/decr[DECR]
|

Expand Down
Expand Up @@ -9,6 +9,7 @@
import org.infinispan.server.resp.commands.INFO;
import org.infinispan.server.resp.commands.connection.AUTH;
import org.infinispan.server.resp.commands.connection.COMMAND;
import org.infinispan.server.resp.commands.connection.DBSIZE;
import org.infinispan.server.resp.commands.connection.ECHO;
import org.infinispan.server.resp.commands.connection.HELLO;
import org.infinispan.server.resp.commands.connection.MODULE;
Expand Down Expand Up @@ -95,7 +96,7 @@ public String getName() {
indexedRespCommand[0] = new RespCommand[]{new APPEND(), new AUTH()};
indexedRespCommand[2] = new RespCommand[]{new CONFIG(), new COMMAND()};
// DEL should always be first here
indexedRespCommand[3] = new RespCommand[]{new DEL(), new DECR(), new DECRBY()};
indexedRespCommand[3] = new RespCommand[]{new DEL(), new DECR(), new DECRBY(), new DBSIZE()};
indexedRespCommand[4] = new RespCommand[]{new ECHO()};
// GET should always be first here
indexedRespCommand[6] = new RespCommand[]{new GET(), new GETDEL()};
Expand Down
@@ -0,0 +1,29 @@
package org.infinispan.server.resp.commands.connection;

import java.util.List;
import java.util.concurrent.CompletionStage;

import org.infinispan.server.resp.Consumers;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;

import io.netty.channel.ChannelHandlerContext;

/**
* <a href="https://redis.io/commands/dbsize/">DBSIZE</a>
*
* @since 15.0
*/
public class DBSIZE extends RespCommand implements Resp3Command {
public DBSIZE() {
super(1, 0, 0, 0);
}

@Override
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx,
List<byte[]> arguments) {
return handler.stageToReturn(handler.cache().sizeAsync(), ctx, Consumers.LONG_BICONSUMER);
}
}
Expand Up @@ -606,6 +606,15 @@ public void testModule() {
assertEquals(0, response.size());
}

@Test
public void testDbSize() {
RedisCommands<String, String> redis = redisConnection.sync();
Long size = redis.dbsize();
assertThat(size).isEqualTo(cache.size());
redis.set("dbsize-key", "dbsize-value");
assertThat(redis.dbsize()).isEqualTo(size + 1);
}

public static class SimpleCommand implements ProtocolKeyword {
private final String name;

Expand Down

0 comments on commit e18dbcc

Please sign in to comment.