You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2021/04/19 23:11:41 UTC
[geode] branch support/1.14 updated: GEODE-8932: Support Redis
SETNX command (#6016)
This is an automated email from the ASF dual-hosted git repository.
nnag pushed a commit to branch support/1.14
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/support/1.14 by this push:
new 9e16cf8 GEODE-8932: Support Redis SETNX command (#6016)
9e16cf8 is described below
commit 9e16cf85c2c66542fa8dd229e42e6c1b17a6fc7c
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Tue Feb 16 06:49:13 2021 -0800
GEODE-8932: Support Redis SETNX command (#6016)
(cherry picked from commit 22eef1c587386465e687a010ab7de4b65041fe1c)
---
.../string/AbstractSetNXIntegrationTest.java | 36 +++++++++++++++++-----
.../geode/redis/internal/RedisCommandType.java | 2 +-
.../redis/internal/SupportedCommandsJUnitTest.java | 2 +-
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractSetNXIntegrationTest.java b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractSetNXIntegrationTest.java
index 2a12d67..9f1538f 100755
--- a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractSetNXIntegrationTest.java
+++ b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractSetNXIntegrationTest.java
@@ -17,12 +17,15 @@ package org.apache.geode.redis.internal.executor.string;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.util.concurrent.atomic.AtomicLong;
+
import org.junit.After;
import org.junit.Before;
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;
@@ -62,12 +65,18 @@ public abstract class AbstractSetNXIntegrationTest implements RedisPortSupplier
}
@Test
+ public void testSetNXonNonString_doesNotThrowError() {
+ jedis.sadd("set", "a");
+ assertThat(jedis.setnx("set", "b")).isEqualTo(0);
+
+ jedis.hset("hash", "a", "b");
+ assertThat(jedis.setnx("hash", "b")).isEqualTo(0);
+ }
+
+ @Test
public void testSetNX() {
- String key1 = randString();
- String key2;
- do {
- key2 = randString();
- } while (key2.equals(key1));
+ String key1 = "some-random-string";
+ String key2 = "some-other-random-string";
long response1 = jedis.setnx(key1, key1);
long response2 = jedis.setnx(key2, key2);
@@ -78,7 +87,20 @@ public abstract class AbstractSetNXIntegrationTest implements RedisPortSupplier
assertThat(response3).isEqualTo(0);
}
- private String randString() {
- return Long.toHexString(Double.doubleToLongBits(Math.random()));
+ @Test
+ public void testSetNX_whenCalledConcurrently() {
+ Jedis jedis2 = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+ AtomicLong updateCount = new AtomicLong(0);
+ int iterations = 10000;
+
+ new ConcurrentLoopingThreads(iterations,
+ (i) -> updateCount.getAndAdd(jedis.setnx("key-" + i, "value-" + i)),
+ (i) -> updateCount.getAndAdd(jedis2.setnx("key-" + i, "value-" + i)))
+ .runInLockstep();
+
+ assertThat(iterations).isEqualTo(updateCount.get());
+
+ jedis2.close();
}
+
}
diff --git a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
index 4bcc27e..e023f90 100755
--- a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
+++ b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
@@ -155,6 +155,7 @@ public enum RedisCommandType {
INCRBYFLOAT(new IncrByFloatExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
MGET(new MGetExecutor(), SUPPORTED, new MinimumParameterRequirements(2)),
SET(new SetExecutor(), SUPPORTED, new MinimumParameterRequirements(3)),
+ SETNX(new SetNXExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
STRLEN(new StrlenExecutor(), SUPPORTED, new ExactParameterRequirements(2)),
/************* Hashes *****************/
@@ -237,7 +238,6 @@ public enum RedisCommandType {
PSETEX(new PSetEXExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
SETBIT(new SetBitExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
SETEX(new SetEXExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
- SETNX(new SetNXExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
SETRANGE(new SetRangeExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
/**************** Sets *****************/
diff --git a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
index ce49e20..4f4681f 100644
--- a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
+++ b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
@@ -71,6 +71,7 @@ public class SupportedCommandsJUnitTest {
"SADD",
"SET",
"SLOWLOG",
+ "SETNX",
"SMEMBERS",
"SREM",
"STRLEN",
@@ -103,7 +104,6 @@ public class SupportedCommandsJUnitTest {
"SELECT",
"SETBIT",
"SETEX",
- "SETNX",
"SETRANGE",
"SHUTDOWN",
"SINTER",