You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2021/02/16 14:51:47 UTC
[geode] branch develop updated: GEODE-8931: Support Redis GETRANGE
command (#6015)
This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new f8413bc GEODE-8931: Support Redis GETRANGE command (#6015)
f8413bc is described below
commit f8413bc6c0220007af0237592c7c23f571cd6fbc
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Tue Feb 16 06:49:51 2021 -0800
GEODE-8931: Support Redis GETRANGE command (#6015)
---
.../string/AbstractGetRangeIntegrationTest.java | 38 ++++++++++++++++++++++
.../geode/redis/internal/RedisCommandType.java | 2 +-
.../redis/internal/SupportedCommandsJUnitTest.java | 2 +-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java b/geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
index 5d762f0..8f5d21f 100755
--- a/geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
+++ b/geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
@@ -15,10 +15,12 @@
package org.apache.geode.redis.internal.executor.string;
import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.charset.StandardCharsets;
+import java.util.Random;
import org.junit.After;
import org.junit.Before;
@@ -26,11 +28,13 @@ import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
+import org.apache.geode.redis.ConcurrentLoopingThreads;
import org.apache.geode.test.awaitility.GeodeAwaitility;
import org.apache.geode.test.dunit.rules.RedisPortSupplier;
public abstract class AbstractGetRangeIntegrationTest implements RedisPortSupplier {
+ private Random random = new Random();
private Jedis jedis;
private static final int REDIS_CLIENT_TIMEOUT =
Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
@@ -86,6 +90,28 @@ public abstract class AbstractGetRangeIntegrationTest implements RedisPortSuppli
}
@Test
+ public void givenRangeIsBiggerThanMinOrMax_returnsNotIntegerError() {
+ assertThatThrownBy(
+ () -> jedis.sendCommand(Protocol.Command.GETRANGE, "key", "0", "9223372036854775808"))
+ .hasMessage("ERR " + ERROR_NOT_INTEGER);
+
+ assertThatThrownBy(
+ () -> jedis.sendCommand(Protocol.Command.GETRANGE, "key", "0", "-9223372036854775809"))
+ .hasMessage("ERR " + ERROR_NOT_INTEGER);
+ }
+
+ @Test
+ public void givenWrongType_returnsWrongTypeError() {
+ jedis.sadd("set", "value");
+ assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.GETRANGE, "set", "0", "1"))
+ .hasMessage("WRONGTYPE " + ERROR_WRONG_TYPE);
+
+ jedis.hset("hash", "field", "value");
+ assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.GETRANGE, "hash", "0", "1"))
+ .hasMessage("WRONGTYPE " + ERROR_WRONG_TYPE);
+ }
+
+ @Test
public void testGetRange_whenWholeRangeSpecified_returnsEntireValue() {
String key = "key";
String valueWith19Characters = "abc123babyyouknowme";
@@ -248,4 +274,16 @@ public abstract class AbstractGetRangeIntegrationTest implements RedisPortSuppli
String range = jedis.getrange(key, 7, 14);
assertThat(range).isEqualTo("");
}
+
+ @Test
+ public void testConcurrentGetrange_whileUpdating() {
+ Jedis jedis2 = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+ jedis.set("key", "1");
+
+ new ConcurrentLoopingThreads(10000,
+ (i) -> jedis.set("key", Integer.toString(random.nextInt(10000))),
+ (i) -> Integer.parseInt(jedis2.getrange("key", 0, 5)))
+ .run();
+ }
+
}
diff --git a/geode-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java b/geode-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
index ead94c9..1140604 100755
--- a/geode-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
+++ b/geode-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
@@ -152,6 +152,7 @@ public enum RedisCommandType {
APPEND(new AppendExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
DECR(new DecrExecutor(), SUPPORTED, new ExactParameterRequirements(2)),
GET(new GetExecutor(), SUPPORTED, new ExactParameterRequirements(2)),
+ GETRANGE(new GetRangeExecutor(), SUPPORTED, new ExactParameterRequirements(4)),
INCRBYFLOAT(new IncrByFloatExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
MGET(new MGetExecutor(), SUPPORTED, new MinimumParameterRequirements(2)),
SET(new SetExecutor(), SUPPORTED, new MinimumParameterRequirements(3)),
@@ -225,7 +226,6 @@ public enum RedisCommandType {
BITPOS(new BitPosExecutor(), UNSUPPORTED, new MinimumParameterRequirements(3)),
DECRBY(new DecrByExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
GETBIT(new GetBitExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
- GETRANGE(new GetRangeExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
GETSET(new GetSetExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
INCR(new IncrExecutor(), UNSUPPORTED, new ExactParameterRequirements(2)),
INCRBY(new IncrByExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
diff --git a/geode-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java b/geode-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
index 0e3f194..065681a 100644
--- a/geode-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
+++ b/geode-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
@@ -38,6 +38,7 @@ public class SupportedCommandsJUnitTest {
"EXPIRE",
"EXPIREAT",
"GET",
+ "GETRANGE",
"HGET",
"HDEL",
"HEXISTS",
@@ -87,7 +88,6 @@ public class SupportedCommandsJUnitTest {
"FLUSHALL",
"FLUSHDB",
"GETBIT",
- "GETRANGE",
"GETSET",
"HSCAN",
"INCR",