Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-14880 RESP DBSIZE #10956

Merged
merged 1 commit into from May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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