Skip to content

Commit

Permalink
ISPN-16752 SRANDMEMBER incorrect error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rigazilla authored and wburns committed Oct 15, 2024
1 parent a600432 commit 40d00b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.infinispan.server.resp.Consumers;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespErrorUtil;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.ArgumentUtils;
import org.infinispan.server.resp.commands.Resp3Command;
Expand All @@ -28,6 +29,10 @@ public CompletionStage<RespRequestHandler> perform(Resp3Handler handler,
ChannelHandlerContext ctx,
List<byte[]> arguments) {
final Long count = (arguments.size() <= 1) ? 1 : ArgumentUtils.toLong(arguments.get(1));
if (count == Long.MIN_VALUE) {
RespErrorUtil.customError("value is out of range, value must between -9223372036854775807 and 9223372036854775807", handler.allocator());
return handler.myStage();
}
final byte[] key = arguments.get(0);
EmbeddedSetCache<byte[], byte[]> esc = handler.getEmbeddedSetCache();
return handler.stageToReturn(esc.pop(key, count, false), ctx, Consumers.COLLECTION_BULK_BICONSUMER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ public void testSpop() {
assertWrongType(() -> redis.lpush("listleads", "tristan"), () -> redis.spop("listleads", 1));
}

@Test
public void testRandmemberMIN_VALUE() {
// Testing special case count = Long.MIN_VAL
RedisCommands<String, String> redis = redisConnection.sync();
String key = "srandmember";
redis.sadd(key, "1", "2", "3");
assertThatThrownBy(() -> {
redis.srandmember(key, Long.MIN_VALUE);
}).isInstanceOf(RedisCommandExecutionException.class)
.hasMessageContaining("ERR value is out of range");
}

@Test
public void testRandmember() {
RedisCommands<String, String> redis = redisConnection.sync();
Expand Down

0 comments on commit 40d00b1

Please sign in to comment.