From bb83e5768c52a9c469d611e099a9a241b0d4c0ff Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 11:52:03 +0800 Subject: [PATCH 01/39] move pagckage --- pom.xml | 1 + .../funkye/redispike}/ProxyMain.java | 2 +- .../redis2asp => icu/funkye/redispike}/Server.java | 12 ++++++------ .../funkye/redispike}/common/BoltServer.java | 2 +- .../redispike}/common/CONNECTEventProcessor.java | 2 +- .../redispike}/common/DISCONNECTEventProcessor.java | 2 +- .../redispike}/factory/AeroSpikeClientFactory.java | 2 +- .../redispike}/protocol/RedisCommandDecoder.java | 10 +++++----- .../redispike}/protocol/RedisCommandEncoder.java | 2 +- .../redispike}/protocol/RedisCommandHandler.java | 12 ++++++------ .../funkye/redispike}/protocol/RedisProtocol.java | 2 +- .../funkye/redispike}/protocol/RedisRequest.java | 2 +- .../funkye/redispike}/protocol/RedisResponse.java | 2 +- .../redispike}/protocol/request/CommandRequest.java | 8 ++++---- .../redispike}/protocol/request/DelRequest.java | 8 ++++---- .../redispike}/protocol/request/GetRequest.java | 8 ++++---- .../redispike}/protocol/request/SetRequest.java | 10 +++++----- .../redispike}/protocol/response/BulkResponse.java | 4 ++-- .../protocol/response/IntegerResponse.java | 4 ++-- .../funkye/redispike}/ServerTest.java | 4 ++-- 20 files changed, 50 insertions(+), 49 deletions(-) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/ProxyMain.java (97%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/Server.java (93%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/common/BoltServer.java (98%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/common/CONNECTEventProcessor.java (98%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/common/DISCONNECTEventProcessor.java (98%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/factory/AeroSpikeClientFactory.java (98%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisCommandDecoder.java (94%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisCommandEncoder.java (97%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisCommandHandler.java (96%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisProtocol.java (97%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisRequest.java (95%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/RedisResponse.java (98%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/request/CommandRequest.java (85%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/request/DelRequest.java (87%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/request/GetRequest.java (86%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/request/SetRequest.java (92%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/response/BulkResponse.java (95%) rename src/main/java/{org/redis2asp => icu/funkye/redispike}/protocol/response/IntegerResponse.java (94%) rename src/test/java/{org/redis2asp => icu/funkye/redispike}/ServerTest.java (98%) diff --git a/pom.xml b/pom.xml index 21976a7..eb7089b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,7 @@ 1.0-SNAPSHOT + icu.funkye.redispike.ProxyMain 1.8 1.8 UTF-8 diff --git a/src/main/java/org/redis2asp/ProxyMain.java b/src/main/java/icu/funkye/redispike/ProxyMain.java similarity index 97% rename from src/main/java/org/redis2asp/ProxyMain.java rename to src/main/java/icu/funkye/redispike/ProxyMain.java index 15f62ae..554b10b 100644 --- a/src/main/java/org/redis2asp/ProxyMain.java +++ b/src/main/java/icu/funkye/redispike/ProxyMain.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp; +package icu.funkye.redispike; import org.apache.commons.cli.ParseException; diff --git a/src/main/java/org/redis2asp/Server.java b/src/main/java/icu/funkye/redispike/Server.java similarity index 93% rename from src/main/java/org/redis2asp/Server.java rename to src/main/java/icu/funkye/redispike/Server.java index 134c90f..4a17687 100644 --- a/src/main/java/org/redis2asp/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp; +package icu.funkye.redispike; import com.aerospike.client.Host; import com.aerospike.client.policy.ClientPolicy; @@ -25,11 +25,11 @@ import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.redis2asp.common.BoltServer; -import org.redis2asp.common.CONNECTEventProcessor; -import org.redis2asp.common.DISCONNECTEventProcessor; -import org.redis2asp.factory.AeroSpikeClientFactory; -import org.redis2asp.protocol.RedisProtocol; +import icu.funkye.redispike.common.BoltServer; +import icu.funkye.redispike.common.CONNECTEventProcessor; +import icu.funkye.redispike.common.DISCONNECTEventProcessor; +import icu.funkye.redispike.factory.AeroSpikeClientFactory; +import icu.funkye.redispike.protocol.RedisProtocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/redis2asp/common/BoltServer.java b/src/main/java/icu/funkye/redispike/common/BoltServer.java similarity index 98% rename from src/main/java/org/redis2asp/common/BoltServer.java rename to src/main/java/icu/funkye/redispike/common/BoltServer.java index ba25a0e..52fd8ac 100644 --- a/src/main/java/org/redis2asp/common/BoltServer.java +++ b/src/main/java/icu/funkye/redispike/common/BoltServer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.common; +package icu.funkye.redispike.common; import com.alipay.remoting.ConnectionEventProcessor; import com.alipay.remoting.ConnectionEventType; diff --git a/src/main/java/org/redis2asp/common/CONNECTEventProcessor.java b/src/main/java/icu/funkye/redispike/common/CONNECTEventProcessor.java similarity index 98% rename from src/main/java/org/redis2asp/common/CONNECTEventProcessor.java rename to src/main/java/icu/funkye/redispike/common/CONNECTEventProcessor.java index c1737a7..64c936c 100644 --- a/src/main/java/org/redis2asp/common/CONNECTEventProcessor.java +++ b/src/main/java/icu/funkye/redispike/common/CONNECTEventProcessor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.common; +package icu.funkye.redispike.common; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/org/redis2asp/common/DISCONNECTEventProcessor.java b/src/main/java/icu/funkye/redispike/common/DISCONNECTEventProcessor.java similarity index 98% rename from src/main/java/org/redis2asp/common/DISCONNECTEventProcessor.java rename to src/main/java/icu/funkye/redispike/common/DISCONNECTEventProcessor.java index 71eeaae..00991c6 100644 --- a/src/main/java/org/redis2asp/common/DISCONNECTEventProcessor.java +++ b/src/main/java/icu/funkye/redispike/common/DISCONNECTEventProcessor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.common; +package icu.funkye.redispike.common; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/org/redis2asp/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java similarity index 98% rename from src/main/java/org/redis2asp/factory/AeroSpikeClientFactory.java rename to src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index 6bee1f8..d674659 100644 --- a/src/main/java/org/redis2asp/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.factory; +package icu.funkye.redispike.factory; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; diff --git a/src/main/java/org/redis2asp/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java similarity index 94% rename from src/main/java/org/redis2asp/protocol/RedisCommandDecoder.java rename to src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index ddbb464..c659ab1 100644 --- a/src/main/java/org/redis2asp/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -23,10 +23,10 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.DecoderException; -import org.redis2asp.protocol.request.CommandRequest; -import org.redis2asp.protocol.request.DelRequest; -import org.redis2asp.protocol.request.GetRequest; -import org.redis2asp.protocol.request.SetRequest; +import icu.funkye.redispike.protocol.request.CommandRequest; +import icu.funkye.redispike.protocol.request.DelRequest; +import icu.funkye.redispike.protocol.request.GetRequest; +import icu.funkye.redispike.protocol.request.SetRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/redis2asp/protocol/RedisCommandEncoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java similarity index 97% rename from src/main/java/org/redis2asp/protocol/RedisCommandEncoder.java rename to src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java index ff9dc69..174ad8f 100644 --- a/src/main/java/org/redis2asp/protocol/RedisCommandEncoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; import java.io.Serializable; import com.alipay.remoting.CommandEncoder; diff --git a/src/main/java/org/redis2asp/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java similarity index 96% rename from src/main/java/org/redis2asp/protocol/RedisCommandHandler.java rename to src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index 4740e86..6a8a188 100644 --- a/src/main/java/org/redis2asp/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; import java.nio.charset.StandardCharsets; import java.util.List; @@ -37,11 +37,11 @@ import com.alipay.remoting.RemotingContext; import com.alipay.remoting.RemotingProcessor; import com.alipay.sofa.common.profile.StringUtil; -import org.redis2asp.factory.AeroSpikeClientFactory; -import org.redis2asp.protocol.request.CommandRequest; -import org.redis2asp.protocol.request.DelRequest; -import org.redis2asp.protocol.request.GetRequest; -import org.redis2asp.protocol.request.SetRequest; +import icu.funkye.redispike.factory.AeroSpikeClientFactory; +import icu.funkye.redispike.protocol.request.CommandRequest; +import icu.funkye.redispike.protocol.request.DelRequest; +import icu.funkye.redispike.protocol.request.GetRequest; +import icu.funkye.redispike.protocol.request.SetRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/redis2asp/protocol/RedisProtocol.java b/src/main/java/icu/funkye/redispike/protocol/RedisProtocol.java similarity index 97% rename from src/main/java/org/redis2asp/protocol/RedisProtocol.java rename to src/main/java/icu/funkye/redispike/protocol/RedisProtocol.java index 8c88214..5a27af3 100644 --- a/src/main/java/org/redis2asp/protocol/RedisProtocol.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisProtocol.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; import com.alipay.remoting.CommandDecoder; import com.alipay.remoting.CommandEncoder; diff --git a/src/main/java/org/redis2asp/protocol/RedisRequest.java b/src/main/java/icu/funkye/redispike/protocol/RedisRequest.java similarity index 95% rename from src/main/java/org/redis2asp/protocol/RedisRequest.java rename to src/main/java/icu/funkye/redispike/protocol/RedisRequest.java index 53df565..9f6d275 100644 --- a/src/main/java/org/redis2asp/protocol/RedisRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisRequest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; public interface RedisRequest { diff --git a/src/main/java/org/redis2asp/protocol/RedisResponse.java b/src/main/java/icu/funkye/redispike/protocol/RedisResponse.java similarity index 98% rename from src/main/java/org/redis2asp/protocol/RedisResponse.java rename to src/main/java/icu/funkye/redispike/protocol/RedisResponse.java index e0929f8..fd3a72b 100644 --- a/src/main/java/org/redis2asp/protocol/RedisResponse.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisResponse.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol; +package icu.funkye.redispike.protocol; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/org/redis2asp/protocol/request/CommandRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/CommandRequest.java similarity index 85% rename from src/main/java/org/redis2asp/protocol/request/CommandRequest.java rename to src/main/java/icu/funkye/redispike/protocol/request/CommandRequest.java index 33d58c7..dc54fc7 100644 --- a/src/main/java/org/redis2asp/protocol/request/CommandRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/CommandRequest.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.request; +package icu.funkye.redispike.protocol.request; -import org.redis2asp.protocol.RedisRequest; -import org.redis2asp.protocol.RedisResponse; -import org.redis2asp.protocol.response.BulkResponse; +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.BulkResponse; public class CommandRequest implements RedisRequest { diff --git a/src/main/java/org/redis2asp/protocol/request/DelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java similarity index 87% rename from src/main/java/org/redis2asp/protocol/request/DelRequest.java rename to src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java index 5e30b1d..4c96e9b 100644 --- a/src/main/java/org/redis2asp/protocol/request/DelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.request; +package icu.funkye.redispike.protocol.request; import java.util.List; -import org.redis2asp.protocol.RedisRequest; -import org.redis2asp.protocol.RedisResponse; -import org.redis2asp.protocol.response.IntegerResponse; +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.IntegerResponse; public class DelRequest implements RedisRequest { diff --git a/src/main/java/org/redis2asp/protocol/request/GetRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/GetRequest.java similarity index 86% rename from src/main/java/org/redis2asp/protocol/request/GetRequest.java rename to src/main/java/icu/funkye/redispike/protocol/request/GetRequest.java index 3ccd6b0..7e82588 100644 --- a/src/main/java/org/redis2asp/protocol/request/GetRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/GetRequest.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.request; +package icu.funkye.redispike.protocol.request; -import org.redis2asp.protocol.RedisRequest; -import org.redis2asp.protocol.RedisResponse; -import org.redis2asp.protocol.response.BulkResponse; +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.BulkResponse; public class GetRequest implements RedisRequest { diff --git a/src/main/java/org/redis2asp/protocol/request/SetRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java similarity index 92% rename from src/main/java/org/redis2asp/protocol/request/SetRequest.java rename to src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java index f4c61ac..92d2fb6 100644 --- a/src/main/java/org/redis2asp/protocol/request/SetRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.request; +package icu.funkye.redispike.protocol.request; import java.nio.charset.StandardCharsets; import java.util.List; -import org.redis2asp.protocol.RedisRequest; -import org.redis2asp.protocol.RedisResponse; -import org.redis2asp.protocol.response.BulkResponse; -import org.redis2asp.protocol.response.IntegerResponse; +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.BulkResponse; +import icu.funkye.redispike.protocol.response.IntegerResponse; public class SetRequest implements RedisRequest { diff --git a/src/main/java/org/redis2asp/protocol/response/BulkResponse.java b/src/main/java/icu/funkye/redispike/protocol/response/BulkResponse.java similarity index 95% rename from src/main/java/org/redis2asp/protocol/response/BulkResponse.java rename to src/main/java/icu/funkye/redispike/protocol/response/BulkResponse.java index 70465f6..d367eea 100644 --- a/src/main/java/org/redis2asp/protocol/response/BulkResponse.java +++ b/src/main/java/icu/funkye/redispike/protocol/response/BulkResponse.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.response; +package icu.funkye.redispike.protocol.response; import java.io.IOException; import java.util.Arrays; import io.netty.buffer.ByteBuf; -import org.redis2asp.protocol.RedisResponse; +import icu.funkye.redispike.protocol.RedisResponse; public class BulkResponse implements RedisResponse { diff --git a/src/main/java/org/redis2asp/protocol/response/IntegerResponse.java b/src/main/java/icu/funkye/redispike/protocol/response/IntegerResponse.java similarity index 94% rename from src/main/java/org/redis2asp/protocol/response/IntegerResponse.java rename to src/main/java/icu/funkye/redispike/protocol/response/IntegerResponse.java index 7e2196b..75615e0 100644 --- a/src/main/java/org/redis2asp/protocol/response/IntegerResponse.java +++ b/src/main/java/icu/funkye/redispike/protocol/response/IntegerResponse.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp.protocol.response; +package icu.funkye.redispike.protocol.response; import java.io.IOException; import java.nio.charset.StandardCharsets; import io.netty.buffer.ByteBuf; -import org.redis2asp.protocol.RedisResponse; +import icu.funkye.redispike.protocol.RedisResponse; public class IntegerResponse implements RedisResponse { diff --git a/src/test/java/org/redis2asp/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java similarity index 98% rename from src/test/java/org/redis2asp/ServerTest.java rename to src/test/java/icu/funkye/redispike/ServerTest.java index 886eb93..5088c26 100644 --- a/src/test/java/org/redis2asp/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redis2asp; +package icu.funkye.redispike; import java.io.IOException; import java.util.ArrayList; @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.redis2asp.factory.AeroSpikeClientFactory; +import icu.funkye.redispike.factory.AeroSpikeClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; From 6c4d70cbf90adfece9c222ba70b03d0bec0de9e0 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 15:33:48 +0800 Subject: [PATCH 02/39] feature: Add performance report and help prompt --- README.md | 78 +++++++++++++++++++ pom.xml | 31 ++++++-- .../java/icu/funkye/redispike/Server.java | 22 +++++- .../protocol/RedisCommandDecoder.java | 4 +- .../protocol/RedisCommandEncoder.java | 1 - .../protocol/RedisCommandHandler.java | 50 +++++++----- .../protocol/request/DelRequest.java | 7 ++ src/main/resources/logback.xml | 14 ++-- 8 files changed, 173 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 149d796..8277b66 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,80 @@ # redis2asp High-performance Aerospike proxy for the Redis protocol +### Performance Test Report +aerospike 3.x 2c4g redispike-proxy 2c4g: +./redis-benchmark -h xxxx -p 6379 -n 2000000 -c 200 -t get +``` +WARNING: Could not fetch server CONFIG +====== GET ====== +2000000 requests completed in 44.94 seconds +200 parallel clients +3 bytes payload +keep alive: 1 +multi-thread: no + +Latency by percentile distribution: +0.000% <= 1.975 milliseconds (cumulative count 1) +50.000% <= 3.879 milliseconds (cumulative count 1001535) +75.000% <= 4.919 milliseconds (cumulative count 1501029) +87.500% <= 5.999 milliseconds (cumulative count 1750484) +93.750% <= 7.247 milliseconds (cumulative count 1875200) +96.875% <= 8.599 milliseconds (cumulative count 1937780) +98.438% <= 10.071 milliseconds (cumulative count 1968821) +99.219% <= 12.023 milliseconds (cumulative count 1984401) +99.609% <= 13.967 milliseconds (cumulative count 1992202) +99.805% <= 16.071 milliseconds (cumulative count 1996100) +99.902% <= 19.199 milliseconds (cumulative count 1998053) +99.951% <= 22.271 milliseconds (cumulative count 1999027) +99.976% <= 24.847 milliseconds (cumulative count 1999515) +99.988% <= 26.831 milliseconds (cumulative count 1999756) +99.994% <= 30.527 milliseconds (cumulative count 1999879) +99.997% <= 31.231 milliseconds (cumulative count 1999942) +99.998% <= 31.535 milliseconds (cumulative count 1999971) +99.999% <= 31.663 milliseconds (cumulative count 1999988) +100.000% <= 31.743 milliseconds (cumulative count 1999993) +100.000% <= 31.807 milliseconds (cumulative count 1999997) +100.000% <= 31.871 milliseconds (cumulative count 1999999) +100.000% <= 31.919 milliseconds (cumulative count 2000000) +100.000% <= 31.919 milliseconds (cumulative count 2000000) + +Cumulative distribution of latencies: +0.000% <= 0.103 milliseconds (cumulative count 0) +0.001% <= 2.007 milliseconds (cumulative count 10) +0.051% <= 2.103 milliseconds (cumulative count 1012) +22.646% <= 3.103 milliseconds (cumulative count 452915) +56.697% <= 4.103 milliseconds (cumulative count 1133935) +78.001% <= 5.103 milliseconds (cumulative count 1560018) +88.276% <= 6.103 milliseconds (cumulative count 1765529) +93.275% <= 7.103 milliseconds (cumulative count 1865499) +95.983% <= 8.103 milliseconds (cumulative count 1919661) +97.593% <= 9.103 milliseconds (cumulative count 1951867) +98.460% <= 10.103 milliseconds (cumulative count 1969205) +98.949% <= 11.103 milliseconds (cumulative count 1978987) +99.238% <= 12.103 milliseconds (cumulative count 1984763) +99.451% <= 13.103 milliseconds (cumulative count 1989027) +99.629% <= 14.103 milliseconds (cumulative count 1992578) +99.732% <= 15.103 milliseconds (cumulative count 1994648) +99.808% <= 16.103 milliseconds (cumulative count 1996153) +99.853% <= 17.103 milliseconds (cumulative count 1997051) +99.878% <= 18.111 milliseconds (cumulative count 1997563) +99.899% <= 19.103 milliseconds (cumulative count 1997985) +99.918% <= 20.111 milliseconds (cumulative count 1998363) +99.936% <= 21.103 milliseconds (cumulative count 1998710) +99.949% <= 22.111 milliseconds (cumulative count 1998981) +99.962% <= 23.103 milliseconds (cumulative count 1999237) +99.969% <= 24.111 milliseconds (cumulative count 1999375) +99.979% <= 25.103 milliseconds (cumulative count 1999573) +99.984% <= 26.111 milliseconds (cumulative count 1999674) +99.990% <= 27.103 milliseconds (cumulative count 1999795) +99.991% <= 28.111 milliseconds (cumulative count 1999828) +99.993% <= 29.103 milliseconds (cumulative count 1999854) +99.993% <= 30.111 milliseconds (cumulative count 1999862) +99.997% <= 31.103 milliseconds (cumulative count 1999932) +100.000% <= 32.111 milliseconds (cumulative count 2000000) + +Summary: +throughput summary: 44501.80 requests per second +latency summary (msec): +avg min p50 p95 p99 max +4.337 1.968 3.879 7.679 11.255 31.919 +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index eb7089b..7c65275 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example - redis2asp + icu.funkye + redispike-proxy 1.0-SNAPSHOT @@ -40,7 +40,7 @@ com.aerospike aerospike-client - 7.2.1 + 4.1.2 commons-cli @@ -70,11 +70,32 @@ + ${artifactId} org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 + maven-assembly-plugin + 3.3.0 + + + + ${start-class} + + + + jar-with-dependencies + + false + + + + make-assembly + package + + single + + + org.apache.maven.plugins diff --git a/src/main/java/icu/funkye/redispike/Server.java b/src/main/java/icu/funkye/redispike/Server.java index 4a17687..bc506a0 100644 --- a/src/main/java/icu/funkye/redispike/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -16,6 +16,9 @@ */ package icu.funkye.redispike; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Optional; import com.aerospike.client.Host; import com.aerospike.client.policy.ClientPolicy; import com.alipay.remoting.ConnectionEventType; @@ -23,6 +26,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import icu.funkye.redispike.common.BoltServer; @@ -61,8 +65,14 @@ public void start(String... args) throws ParseException { + "for single record and batch commands."); options.addOption("s", "set", true, "Set name. Use 'empty' for empty set (default: demoset)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); + options.addOption("u", "help", false, "Print usage."); + CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args, false); + if (cl.hasOption("u")) { + logUsage(options); + throw new RuntimeException("Terminate after displaying usage"); + } port = Integer.parseInt(cl.getOptionValue("p", "6379")); String host = cl.getOptionValue("th", "127.0.0.1"); int targetPort = Integer.parseInt(cl.getOptionValue("tp", "3000")); @@ -86,8 +96,16 @@ public void start(String... args) throws ParseException { } } - public void shutdown() { - server.stop(); + private void logUsage(Options options) { + HelpFormatter formatter = new HelpFormatter(); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + String syntax = "java -jar redispike-proxy.jar -options"; + formatter.printHelp(pw, 100, syntax, "options:", options, 0, 2, null); + System.out.println(sw); } + public void shutdown() { + Optional.ofNullable(server).ifPresent(BoltServer::stop); + } } diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index c659ab1..c37e3e0 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -53,7 +53,9 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { private RedisRequest convert2RedisRequest(List params) { String cmd = params.get(0); - LOGGER.info("cmd: {}", params); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("cmd: {}", params); + } switch (cmd) { case "get": return new GetRequest(params.get(1)); diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java index 174ad8f..74f5a52 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandEncoder.java @@ -29,7 +29,6 @@ public class RedisCommandEncoder implements CommandEncoder { @Override public void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { - logger.info("RedisCommandEncoder encode"); if (msg instanceof RedisResponse) { RedisResponse redisResponse = (RedisResponse) msg; if (logger.isDebugEnabled()) { diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index 6a8a188..d48c3b5 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -18,15 +18,17 @@ import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import com.aerospike.client.AerospikeException; -import com.aerospike.client.BatchRecord; import com.aerospike.client.Bin; import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Key; import com.aerospike.client.Record; -import com.aerospike.client.listener.BatchRecordArrayListener; import com.aerospike.client.listener.DeleteListener; import com.aerospike.client.listener.RecordListener; import com.aerospike.client.listener.WriteListener; @@ -55,11 +57,13 @@ public class RedisCommandHandler implements CommandHandler { public void handleCommand(RemotingContext ctx, Object msg) { if (msg instanceof RedisRequest) { RedisRequest redisRequest = (RedisRequest) msg; - logger.info("redisRequest:{}", redisRequest); + if(logger.isDebugEnabled()){ + logger.debug("redisRequest:{}", redisRequest); + } if (redisRequest instanceof GetRequest) { GetRequest getRequest = (GetRequest) redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, getRequest.getKey()); - client.get(null, new RecordListener() { + client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { if (record == null) { @@ -101,13 +105,13 @@ public void onFailure(AerospikeException ae) { writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; } if (setRequest.getOperate() == SetRequest.Operate.XX) { - client.get(null, new RecordListener() { + client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { if (record == null) { ctx.writeAndFlush(redisRequest.getResponse()); } else { - client.put(null, new WriteListener() { + client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { @Override public void onSuccess(Key key) { setRequest.setResponse("OK".getBytes(StandardCharsets.UTF_8)); @@ -135,7 +139,7 @@ public void onFailure(AerospikeException ae) { if (writePolicy == null) { writePolicy = client.getWritePolicyDefault(); } - client.put(null, new WriteListener() { + client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { @Override public void onSuccess(Key key) { if (setRequest.getOriginalCommand().contains("nx")) { @@ -163,21 +167,31 @@ public void onFailure(AerospikeException ae) { List keys = delRequest.getKey(); List list = keys.stream().map(key->new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, key)).collect( Collectors.toList()); - client.delete(null, new BatchRecordArrayListener() { - @Override - public void onSuccess(BatchRecord[] records, boolean status) { - if(records!=null&&records.length>0) { - delRequest.setResponse(String.valueOf(records.length).getBytes(StandardCharsets.UTF_8)); + CountDownLatch countDownLatch = new CountDownLatch(list.size()); + for (Key key : list) { + client.delete(AeroSpikeClientFactory.eventLoops.next(), new DeleteListener() { + @Override + public void onSuccess(Key key, boolean b) { + delRequest.setResponse( + String.valueOf(delRequest.getCount().incrementAndGet()).getBytes(StandardCharsets.UTF_8)); + countDownLatch.countDown(); } - ctx.writeAndFlush(delRequest.getResponse()); - } - @Override - public void onFailure(BatchRecord[] records, AerospikeException ae) { - logger.error(ae.getMessage(), ae); + @Override + public void onFailure(AerospikeException e) { + countDownLatch.countDown(); + } + }, client.getWritePolicyDefault(), key); + } + CompletableFuture.runAsync(() -> { + try { + countDownLatch.await(10, TimeUnit.SECONDS); + ctx.writeAndFlush(delRequest.getResponse()); + } catch (InterruptedException e) { + logger.error(e.getMessage(), e); ctx.writeAndFlush(delRequest.getResponse()); } - }, client.getBatchPolicyDefault(), client.getBatchDeletePolicyDefault(), list.toArray(new Key[0])); + }); } } } diff --git a/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java index 4c96e9b..2bbade5 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/DelRequest.java @@ -17,6 +17,7 @@ package icu.funkye.redispike.protocol.request; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import icu.funkye.redispike.protocol.RedisRequest; import icu.funkye.redispike.protocol.RedisResponse; import icu.funkye.redispike.protocol.response.IntegerResponse; @@ -25,6 +26,8 @@ public class DelRequest implements RedisRequest { List key; + AtomicInteger count = new AtomicInteger(0); + IntegerResponse response = new IntegerResponse(); public DelRequest(List key) { @@ -40,6 +43,10 @@ public void setResponse(byte[] data) { this.response.setData(data); } + public AtomicInteger getCount() { + return count; + } + @Override public RedisResponse getResponse() { return response; diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index d341474..fe8fd89 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -20,7 +20,7 @@ + value="${user.home}/logs/redispike-proxy"/> @@ -33,10 +33,10 @@ - ${LOG_FILE_PATH}/${APPLICATION_NAME:-redis2asp}redis2asp.all.log + ${LOG_FILE_PATH}/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.all.log true - ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redis2asp}redis2asp.all.%d{yyyy-MM-dd}.%i.log.gz + ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.all.%d{yyyy-MM-dd}.%i.log.gz 2GB 7 7GB @@ -55,10 +55,10 @@ ACCEPT DENY - ${LOG_FILE_PATH}/${APPLICATION_NAME:-redis2asp}redis2asp.warn.log + ${LOG_FILE_PATH}/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.warn.log true - ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redis2asp}redis2asp.warn.%d{yyyy-MM-dd}.%i.log.gz + ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.warn.%d{yyyy-MM-dd}.%i.log.gz 2GB 7 7GB @@ -77,10 +77,10 @@ ACCEPT DENY - ${LOG_FILE_PATH}/${APPLICATION_NAME:-redis2asp}redis2asp.error.log + ${LOG_FILE_PATH}/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.error.log true - ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redis2asp}redis2asp.error.%d{yyyy-MM-dd}.%i.log.gz + ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-redispike-proxy}redispike-proxy.error.%d{yyyy-MM-dd}.%i.log.gz 2GB 7 7GB From 7745e2056959440bfdafe7fe73163993faabd8fd Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 15:35:53 +0800 Subject: [PATCH 03/39] feature: Add performance report and help prompt --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8277b66..b373c21 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ High-performance Aerospike proxy for the Redis protocol ### Performance Test Report aerospike 3.x 2c4g redispike-proxy 2c4g: -./redis-benchmark -h xxxx -p 6379 -n 2000000 -c 200 -t get + +`./redis-benchmark -h xxxx -p 6379 -n 2000000 -c 200 -t get` ``` WARNING: Could not fetch server CONFIG ====== GET ====== From 0eae9b5a1ab8328a6efd14e7fcf28af403c6e201 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 15:37:58 +0800 Subject: [PATCH 04/39] feature: Add performance report and help prompt --- src/test/java/icu/funkye/redispike/ServerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 5088c26..86ebc3f 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -45,7 +45,7 @@ public class ServerTest { @BeforeAll public static void init() throws IOException, ParseException { server = new Server(); - server.start("-p6789"); + server.start("-p","6789"); aspClient = AeroSpikeClientFactory.getClient(); } From 8bbb7ac135f4498d2939af42e0c71e88a1c80e42 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 15:53:18 +0800 Subject: [PATCH 05/39] feature: Add performance report and help prompt --- pom.xml | 3 ++- .../icu/funkye/redispike/factory/AeroSpikeClientFactory.java | 2 ++ src/test/java/icu/funkye/redispike/ServerTest.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7c65275..273a628 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 1.2.9 1.3.6 3.8 + 7.2.1 @@ -40,7 +41,7 @@ com.aerospike aerospike-client - 4.1.2 + ${asp-client.version} commons-cli diff --git a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index d674659..269f73f 100644 --- a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -21,6 +21,7 @@ import com.aerospike.client.AerospikeClient; import com.aerospike.client.Host; import com.aerospike.client.IAerospikeClient; +import com.aerospike.client.async.AsyncClientPolicy; import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NettyEventLoops; @@ -61,6 +62,7 @@ public static void createInstance(ClientPolicy clientPolicy, Host... hosts) { LOCK.lock(); try { if (client == null) { + clientPolicy.maxConnsPerNode = 65535; clientPolicy.eventLoops = eventLoops; client = new AerospikeClient(clientPolicy, hosts); } diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 86ebc3f..d4afa6d 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -45,7 +45,7 @@ public class ServerTest { @BeforeAll public static void init() throws IOException, ParseException { server = new Server(); - server.start("-p","6789"); + server.start("-p", "6789"); aspClient = AeroSpikeClientFactory.getClient(); } From b07663d94656848c3b6fab41061f2fa05771f743 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 15:53:44 +0800 Subject: [PATCH 06/39] feature: Add performance report and help prompt --- .../icu/funkye/redispike/factory/AeroSpikeClientFactory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index 269f73f..93ee11a 100644 --- a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -21,7 +21,6 @@ import com.aerospike.client.AerospikeClient; import com.aerospike.client.Host; import com.aerospike.client.IAerospikeClient; -import com.aerospike.client.async.AsyncClientPolicy; import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NettyEventLoops; From 393e92fd68217ae628d59bce39f3533707496a01 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:03:56 +0800 Subject: [PATCH 07/39] feature: Add performance report and help prompt --- .../icu/funkye/redispike/factory/AeroSpikeClientFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index 93ee11a..469d966 100644 --- a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -61,7 +61,7 @@ public static void createInstance(ClientPolicy clientPolicy, Host... hosts) { LOCK.lock(); try { if (client == null) { - clientPolicy.maxConnsPerNode = 65535; + clientPolicy.maxConnsPerNode = 300; clientPolicy.eventLoops = eventLoops; client = new AerospikeClient(clientPolicy, hosts); } From a3c46424811310fa3560ae18794a39fa19628cf0 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:07:08 +0800 Subject: [PATCH 08/39] feature: Add performance report and help prompt --- .../icu/funkye/redispike/factory/AeroSpikeClientFactory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index 469d966..d674659 100644 --- a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -61,7 +61,6 @@ public static void createInstance(ClientPolicy clientPolicy, Host... hosts) { LOCK.lock(); try { if (client == null) { - clientPolicy.maxConnsPerNode = 300; clientPolicy.eventLoops = eventLoops; client = new AerospikeClient(clientPolicy, hosts); } From 986c561f0a66d94385592fb44509bdd6f0efeb16 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:11:13 +0800 Subject: [PATCH 09/39] feature: Add performance report and help prompt --- src/main/java/icu/funkye/redispike/Server.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/Server.java b/src/main/java/icu/funkye/redispike/Server.java index bc506a0..6bcbb3e 100644 --- a/src/main/java/icu/funkye/redispike/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -69,10 +69,10 @@ public void start(String... args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args, false); - if (cl.hasOption("u")) { + /* if (cl.hasOption("u")) { logUsage(options); throw new RuntimeException("Terminate after displaying usage"); - } + }*/ port = Integer.parseInt(cl.getOptionValue("p", "6379")); String host = cl.getOptionValue("th", "127.0.0.1"); int targetPort = Integer.parseInt(cl.getOptionValue("tp", "3000")); From 561dc24e8d70d17495aaeebf02998bc043504fb5 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:13:04 +0800 Subject: [PATCH 10/39] feature: Add performance report and help prompt --- src/main/java/icu/funkye/redispike/Server.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/Server.java b/src/main/java/icu/funkye/redispike/Server.java index 6bcbb3e..bc506a0 100644 --- a/src/main/java/icu/funkye/redispike/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -69,10 +69,10 @@ public void start(String... args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args, false); - /* if (cl.hasOption("u")) { + if (cl.hasOption("u")) { logUsage(options); throw new RuntimeException("Terminate after displaying usage"); - }*/ + } port = Integer.parseInt(cl.getOptionValue("p", "6379")); String host = cl.getOptionValue("th", "127.0.0.1"); int targetPort = Integer.parseInt(cl.getOptionValue("tp", "3000")); From c1d088cc57500e2fb3db32b1b27774721fd47a52 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:17:29 +0800 Subject: [PATCH 11/39] test --- src/test/java/icu/funkye/redispike/ServerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index d4afa6d..5e548e1 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -43,9 +43,9 @@ public class ServerTest { static Logger logger = LoggerFactory.getLogger(ServerTest.class); @BeforeAll - public static void init() throws IOException, ParseException { + public static void init() throws ParseException { server = new Server(); - server.start("-p", "6789"); + server.start("-p6789"); aspClient = AeroSpikeClientFactory.getClient(); } From 08e085292103b1c4a9b99ce7a563f36f683180d3 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:21:46 +0800 Subject: [PATCH 12/39] test --- pom.xml | 4 ++-- src/test/java/icu/funkye/redispike/ServerTest.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 273a628..2c1315c 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ ${artifactId} - + org.apache.maven.plugins maven-compiler-plugin diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 5e548e1..c64b463 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -16,7 +16,6 @@ */ package icu.funkye.redispike; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; From 60431d8ad0513e6cd7fb95c7d96622e16de8653c Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:24:41 +0800 Subject: [PATCH 13/39] test --- pom.xml | 4 ++-- src/test/java/icu/funkye/redispike/ServerTest.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2c1315c..273a628 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ ${artifactId} - + org.apache.maven.plugins maven-compiler-plugin diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index c64b463..61b8d97 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -43,9 +43,11 @@ public class ServerTest { @BeforeAll public static void init() throws ParseException { + System.out.println("123123123"); server = new Server(); server.start("-p6789"); aspClient = AeroSpikeClientFactory.getClient(); + System.out.println("123123123"); } @Test From a4447a14ff92f21170df65c0f98d5418ef6f10a6 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:25:23 +0800 Subject: [PATCH 14/39] test --- src/main/java/icu/funkye/redispike/Server.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/icu/funkye/redispike/Server.java b/src/main/java/icu/funkye/redispike/Server.java index bc506a0..21c8ec1 100644 --- a/src/main/java/icu/funkye/redispike/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -69,10 +69,12 @@ public void start(String... args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args, false); + LOGGER.info("server 1!"); if (cl.hasOption("u")) { logUsage(options); throw new RuntimeException("Terminate after displaying usage"); } + LOGGER.info("server 2!"); port = Integer.parseInt(cl.getOptionValue("p", "6379")); String host = cl.getOptionValue("th", "127.0.0.1"); int targetPort = Integer.parseInt(cl.getOptionValue("tp", "3000")); @@ -84,11 +86,13 @@ public void start(String... args) throws ParseException { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.user = targetUser; clientPolicy.password = targetPassword; + LOGGER.info("server 3!"); AeroSpikeClientFactory.createInstance(clientPolicy, hosts); server = new BoltServer(port); server.addConnectionEventProcessor(ConnectionEventType.CONNECT, serverConnectProcessor); server.addConnectionEventProcessor(ConnectionEventType.CLOSE, serverDisConnectProcessor); ProtocolManager.registerProtocol(new RedisProtocol(), RedisProtocol.PROTOCOL_CODE); + LOGGER.info("server 4!"); if (server.start()) { LOGGER.info("server start ok!"); } else { From bd1ca2224f327f9255070b820054f3fad7a4a5dd Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:28:42 +0800 Subject: [PATCH 15/39] test --- pom.xml | 5 +++++ src/main/java/icu/funkye/redispike/Server.java | 4 ---- src/test/java/icu/funkye/redispike/ServerTest.java | 2 -- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 273a628..cbc3a3a 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,11 @@ ${artifactId} + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + org.apache.maven.plugins maven-assembly-plugin diff --git a/src/main/java/icu/funkye/redispike/Server.java b/src/main/java/icu/funkye/redispike/Server.java index 21c8ec1..bc506a0 100644 --- a/src/main/java/icu/funkye/redispike/Server.java +++ b/src/main/java/icu/funkye/redispike/Server.java @@ -69,12 +69,10 @@ public void start(String... args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args, false); - LOGGER.info("server 1!"); if (cl.hasOption("u")) { logUsage(options); throw new RuntimeException("Terminate after displaying usage"); } - LOGGER.info("server 2!"); port = Integer.parseInt(cl.getOptionValue("p", "6379")); String host = cl.getOptionValue("th", "127.0.0.1"); int targetPort = Integer.parseInt(cl.getOptionValue("tp", "3000")); @@ -86,13 +84,11 @@ public void start(String... args) throws ParseException { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.user = targetUser; clientPolicy.password = targetPassword; - LOGGER.info("server 3!"); AeroSpikeClientFactory.createInstance(clientPolicy, hosts); server = new BoltServer(port); server.addConnectionEventProcessor(ConnectionEventType.CONNECT, serverConnectProcessor); server.addConnectionEventProcessor(ConnectionEventType.CLOSE, serverDisConnectProcessor); ProtocolManager.registerProtocol(new RedisProtocol(), RedisProtocol.PROTOCOL_CODE); - LOGGER.info("server 4!"); if (server.start()) { LOGGER.info("server start ok!"); } else { diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 61b8d97..c64b463 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -43,11 +43,9 @@ public class ServerTest { @BeforeAll public static void init() throws ParseException { - System.out.println("123123123"); server = new Server(); server.start("-p6789"); aspClient = AeroSpikeClientFactory.getClient(); - System.out.println("123123123"); } @Test From c3468718bfff7643cd59302476f0f4181fea103c Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:30:33 +0800 Subject: [PATCH 16/39] test --- .../icu/funkye/redispike/factory/AeroSpikeClientFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java index d674659..93ee11a 100644 --- a/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java +++ b/src/main/java/icu/funkye/redispike/factory/AeroSpikeClientFactory.java @@ -61,6 +61,7 @@ public static void createInstance(ClientPolicy clientPolicy, Host... hosts) { LOCK.lock(); try { if (client == null) { + clientPolicy.maxConnsPerNode = 65535; clientPolicy.eventLoops = eventLoops; client = new AerospikeClient(clientPolicy, hosts); } From a98978f6e8f11288cc72047e037b37f095b555b1 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 16:57:10 +0800 Subject: [PATCH 17/39] feature: support hset protocol --- pom.xml | 2 +- .../protocol/RedisCommandDecoder.java | 8 +- .../protocol/RedisCommandHandler.java | 39 ++++++++- .../protocol/request/HSetRequest.java | 85 +++++++++++++++++++ .../protocol/request/SetRequest.java | 24 +----- .../protocol/request/conts/Operate.java | 28 ++++++ .../protocol/request/conts/TtlType.java | 28 ++++++ .../redispike/util/CollectionUtils.java | 33 +++++++ .../java/icu/funkye/redispike/ServerTest.java | 15 +++- 9 files changed, 231 insertions(+), 31 deletions(-) create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/HSetRequest.java create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/conts/Operate.java create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/conts/TtlType.java create mode 100644 src/main/java/icu/funkye/redispike/util/CollectionUtils.java diff --git a/pom.xml b/pom.xml index cbc3a3a..c7861f8 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 1.2.9 1.3.6 3.8 - 7.2.1 + 4.1.2 diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index c37e3e0..3bc2156 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import com.alipay.remoting.CommandDecoder; +import icu.funkye.redispike.protocol.request.HSetRequest; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.DecoderException; @@ -53,14 +54,15 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { private RedisRequest convert2RedisRequest(List params) { String cmd = params.get(0); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("cmd: {}", params); - } + LOGGER.info("cmd: {}", params); switch (cmd) { case "get": return new GetRequest(params.get(1)); case "command": return new CommandRequest(); + case "hset": + case "hsetnx": + return new HSetRequest(params); case "setnx": params.add("nx"); return new SetRequest(params); diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index d48c3b5..7b6a0ec 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -17,6 +17,7 @@ package icu.funkye.redispike.protocol; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; @@ -43,7 +44,10 @@ import icu.funkye.redispike.protocol.request.CommandRequest; import icu.funkye.redispike.protocol.request.DelRequest; import icu.funkye.redispike.protocol.request.GetRequest; +import icu.funkye.redispike.protocol.request.HSetRequest; import icu.funkye.redispike.protocol.request.SetRequest; +import icu.funkye.redispike.protocol.request.conts.Operate; +import icu.funkye.redispike.protocol.request.conts.TtlType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,6 +64,33 @@ public void handleCommand(RemotingContext ctx, Object msg) { if(logger.isDebugEnabled()){ logger.debug("redisRequest:{}", redisRequest); } + if(redisRequest instanceof HSetRequest){ + HSetRequest request = (HSetRequest)redisRequest; + Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); + List list = new ArrayList<>(); + request.getKv().forEach((k,v)->{ + list.add(new Bin(k,v)); + }); + WritePolicy writePolicy; + if(request.getOperate()!=null&&request.getOperate()==Operate.NX){ + writePolicy = new WritePolicy(client.getWritePolicyDefault()); + writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; + }else { + writePolicy = client.getWritePolicyDefault(); + } + client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { + @Override public void onSuccess(Key key) { + request.setResponse( + String.valueOf(request.getKv().size()).getBytes(StandardCharsets.UTF_8)); + ctx.writeAndFlush(redisRequest.getResponse()); + } + + @Override public void onFailure(AerospikeException ae) { + logger.error(ae.getMessage(), ae); + ctx.writeAndFlush(redisRequest.getResponse()); + } + }, writePolicy, key, list.toArray(new Bin[0])); + } if (redisRequest instanceof GetRequest) { GetRequest getRequest = (GetRequest) redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, getRequest.getKey()); @@ -91,7 +122,7 @@ public void onFailure(AerospikeException ae) { WritePolicy writePolicy = null; if (setRequest.getTtl() != null) { writePolicy = new WritePolicy(client.getWritePolicyDefault()); - if (setRequest.getTtlType() == SetRequest.TtlType.EX) { + if (setRequest.getTtlType() == TtlType.EX) { writePolicy.expiration = setRequest.getTtl().intValue(); } else { writePolicy.expiration = Integer.max((int) (setRequest.getTtl() / 1000), 1); @@ -101,10 +132,10 @@ public void onFailure(AerospikeException ae) { if (writePolicy == null) { writePolicy = new WritePolicy(client.getWritePolicyDefault()); } - if (setRequest.getOperate() == SetRequest.Operate.NX) { + if (setRequest.getOperate() == Operate.NX) { writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; - } - if (setRequest.getOperate() == SetRequest.Operate.XX) { + }else + if (setRequest.getOperate() == Operate.XX) { client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HSetRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HSetRequest.java new file mode 100644 index 0000000..62372e4 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/HSetRequest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike.protocol.request; + +import java.util.List; +import java.util.Map; + +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.request.conts.Operate; +import icu.funkye.redispike.protocol.response.IntegerResponse; +import icu.funkye.redispike.util.CollectionUtils; + +public class HSetRequest implements RedisRequest { + + final String originalCommand; + + final String key; + + final Map kv; + + Operate operate; + + RedisResponse response; + + public HSetRequest(List params) { + this.originalCommand = params.remove(0); + this.key = params.remove(0); + this.kv = CollectionUtils.arrayToMap(params); + if (originalCommand.contains("nx")) { + this.operate = Operate.NX; + } else if (params.contains("xx")) { + this.operate = Operate.XX; + } + this.response = new IntegerResponse(); + } + + @Override + public RedisResponse getResponse() { + return this.response; + } + + @Override + public void setResponse(byte[] data) { + this.response.setData(data); + } + + public String getOriginalCommand() { + return originalCommand; + } + + public Map getKv() { + return kv; + } + + public Operate getOperate() { + return operate; + } + + public void setOperate(Operate operate) { + this.operate = operate; + } + + public void setResponse(RedisResponse response) { + this.response = response; + } + + public String getKey() { + return key; + } +} diff --git a/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java index 92d2fb6..e5846a3 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/SetRequest.java @@ -20,6 +20,8 @@ import java.util.List; import icu.funkye.redispike.protocol.RedisRequest; import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.request.conts.Operate; +import icu.funkye.redispike.protocol.request.conts.TtlType; import icu.funkye.redispike.protocol.response.BulkResponse; import icu.funkye.redispike.protocol.response.IntegerResponse; @@ -96,28 +98,6 @@ public String getOriginalCommand() { return originalCommand; } - public enum TtlType { - /** - * EX seconds -- Set the specified expire time, in seconds. - */ - EX, - /** - * PX milliseconds -- Set the specified expire time, in milliseconds. - */ - PX - } - - public enum Operate { - /** - * NX -- Only set the key if it does not already exist. - */ - NX, - /** - * XX -- Only set the key if it already exist. - */ - XX - } - @Override public String toString() { return "SetRequest{" + "originalCommand='" + originalCommand + '\'' + ", key='" + key + '\'' + ", value='" diff --git a/src/main/java/icu/funkye/redispike/protocol/request/conts/Operate.java b/src/main/java/icu/funkye/redispike/protocol/request/conts/Operate.java new file mode 100644 index 0000000..246f054 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/conts/Operate.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike.protocol.request.conts; + +public enum Operate { + /** + * NX -- Only set the key if it does not already exist. + */ + NX, + /** + * XX -- Only set the key if it already exist. + */ + XX +} diff --git a/src/main/java/icu/funkye/redispike/protocol/request/conts/TtlType.java b/src/main/java/icu/funkye/redispike/protocol/request/conts/TtlType.java new file mode 100644 index 0000000..33bfbce --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/conts/TtlType.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike.protocol.request.conts; + +public enum TtlType { + /** + * EX seconds -- Set the specified expire time, in seconds. + */ + EX, + /** + * PX milliseconds -- Set the specified expire time, in milliseconds. + */ + PX +} diff --git a/src/main/java/icu/funkye/redispike/util/CollectionUtils.java b/src/main/java/icu/funkye/redispike/util/CollectionUtils.java new file mode 100644 index 0000000..11d9401 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/util/CollectionUtils.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike.util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CollectionUtils { + + public static Map arrayToMap(List array) { + Map map = new HashMap<>(); + for (int i = 0; i < array.size(); i += 2) { + map.put(array.get(i), array.get(i + 1)); + } + return map; + } + +} diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index c64b463..a3c47ab 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -16,7 +16,9 @@ */ package icu.funkye.redispike; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -44,10 +46,21 @@ public class ServerTest { @BeforeAll public static void init() throws ParseException { server = new Server(); - server.start("-p6789"); + server.start("-th 10.58.10.103 -tp 3000 -n test -s tdkv-test -TU tongdun-admin1 -TP xxxzzz123 -p 6789" + .split(" ")); aspClient = AeroSpikeClientFactory.getClient(); } + @Test + public void testhHset() { + try (Jedis jedis2 = new Jedis("127.0.0.1", 6789)) { + Map a = new HashMap<>(); + Long result = jedis2.hset("a".getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), + "c".getBytes(StandardCharsets.UTF_8)); + Assertions.assertEquals(result, 1); + } + } + @Test public void testRedisSet() { try (Jedis jedis = new Jedis("127.0.0.1", 6379)) { From 66eeda0d42aed3cdd35b3b26766d01b02ab6b85f Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 17:01:39 +0800 Subject: [PATCH 18/39] feature: support hset protocol --- .../java/icu/funkye/redispike/ServerTest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index a3c47ab..5b31c67 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -46,18 +46,26 @@ public class ServerTest { @BeforeAll public static void init() throws ParseException { server = new Server(); - server.start("-th 10.58.10.103 -tp 3000 -n test -s tdkv-test -TU tongdun-admin1 -TP xxxzzz123 -p 6789" + server.start("-p 6789" .split(" ")); aspClient = AeroSpikeClientFactory.getClient(); } @Test public void testhHset() { - try (Jedis jedis2 = new Jedis("127.0.0.1", 6789)) { - Map a = new HashMap<>(); - Long result = jedis2.hset("a".getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), + try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + Long result = jedis.hset("a".getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), "c".getBytes(StandardCharsets.UTF_8)); Assertions.assertEquals(result, 1); + Map map = new HashMap<>(); + map.put("b", "c"); + map.put("d", "e"); + result = jedis.hset("a", map); + Assertions.assertEquals(result, 2); + result = jedis.hsetnx("a","f","g"); + Assertions.assertEquals(result, 1); + result = jedis.hsetnx("a","f","g"); + Assertions.assertEquals(result, 0); } } From 290bc380b38199c3a5e85a9287cf0770df5910c5 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 17:07:02 +0800 Subject: [PATCH 19/39] feature: support hset protocol --- src/test/java/icu/funkye/redispike/ServerTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 5b31c67..3fd13f7 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -53,18 +53,20 @@ public static void init() throws ParseException { @Test public void testhHset() { + String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { - Long result = jedis.hset("a".getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), + Long result = jedis.hset(key.getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), "c".getBytes(StandardCharsets.UTF_8)); Assertions.assertEquals(result, 1); Map map = new HashMap<>(); map.put("b", "c"); map.put("d", "e"); - result = jedis.hset("a", map); + result = jedis.hset(key, map); Assertions.assertEquals(result, 2); - result = jedis.hsetnx("a","f","g"); + key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + result = jedis.hsetnx(key,"f","g"); Assertions.assertEquals(result, 1); - result = jedis.hsetnx("a","f","g"); + result = jedis.hsetnx(key,"f","g"); Assertions.assertEquals(result, 0); } } From e7509c8b3a31f267f9776ff3e9ffe09fb4fac747 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 17:09:06 +0800 Subject: [PATCH 20/39] feature: support hset protocol --- src/test/java/icu/funkye/redispike/ServerTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 3fd13f7..746a353 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -46,8 +46,7 @@ public class ServerTest { @BeforeAll public static void init() throws ParseException { server = new Server(); - server.start("-p 6789" - .split(" ")); + server.start("-p 6789".split(" ")); aspClient = AeroSpikeClientFactory.getClient(); } @@ -64,9 +63,9 @@ public void testhHset() { result = jedis.hset(key, map); Assertions.assertEquals(result, 2); key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - result = jedis.hsetnx(key,"f","g"); + result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 1); - result = jedis.hsetnx(key,"f","g"); + result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 0); } } From b951bc0371586cbd3c3ffb4b964c4ea9a0c2dde7 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 17:15:30 +0800 Subject: [PATCH 21/39] feature: support hset protocol --- .../funkye/redispike/JedisPooledFactory.java | 61 +++++++++++++++++++ .../java/icu/funkye/redispike/ServerTest.java | 17 +++--- 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/test/java/icu/funkye/redispike/JedisPooledFactory.java diff --git a/src/test/java/icu/funkye/redispike/JedisPooledFactory.java b/src/test/java/icu/funkye/redispike/JedisPooledFactory.java new file mode 100644 index 0000000..5fb051a --- /dev/null +++ b/src/test/java/icu/funkye/redispike/JedisPooledFactory.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolAbstract; + +/** + */ +public class JedisPooledFactory { + /** + * The constant LOGGER. + */ + protected static final Logger LOGGER = LoggerFactory.getLogger(JedisPooledFactory.class); + + private static volatile JedisPoolAbstract jedisPool = null; + + /** + * get the RedisPool instance (singleton) + * + * @return redisPool + */ + public static JedisPoolAbstract getJedisPoolInstance(String ip, int port) { + if (jedisPool == null) { + synchronized (JedisPooledFactory.class) { + if (jedisPool == null) { + jedisPool = new JedisPool(ip, port); + } + } + } + return jedisPool; + } + + /** + * get an instance of Jedis (connection) from the connection pool + * + * @return jedis + */ + public static Jedis getJedisInstance() { + return jedisPool.getResource(); + } + +} diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 746a353..b25d1a0 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -47,13 +47,14 @@ public class ServerTest { public static void init() throws ParseException { server = new Server(); server.start("-p 6789".split(" ")); + JedisPooledFactory.getJedisPoolInstance("127.0.0.1", 6789); aspClient = AeroSpikeClientFactory.getClient(); } @Test public void testhHset() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { Long result = jedis.hset(key.getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), "c".getBytes(StandardCharsets.UTF_8)); Assertions.assertEquals(result, 1); @@ -74,7 +75,7 @@ public void testhHset() { public void testRedisSet() { try (Jedis jedis = new Jedis("127.0.0.1", 6379)) { String result = jedis.set("a", "bq"); - try (Jedis jedis2 = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis2 = JedisPooledFactory.getJedisInstance()) { String result2 = jedis2.set("a", "bq"); Assertions.assertEquals(result, result2); } @@ -83,7 +84,7 @@ public void testRedisSet() { @Test public void testGetSetAsp() { - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set("a", "b"); Assertions.assertEquals(result, "OK"); } @@ -108,7 +109,7 @@ public void testGetNilAsp() { @Test public void testSetExAsp() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().ex(1L)); Assertions.assertEquals(result, "OK"); Thread.sleep(3000); @@ -122,7 +123,7 @@ public void testSetExAsp() { @Test public void testSetNxNilAsp() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().nx()); Assertions.assertEquals(result, "OK"); result = jedis.set(key, "b", SetParams.setParams().nx()); @@ -138,7 +139,7 @@ public void testSetNxNilAsp() { @Test public void testSetExNxAsp() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().nx().ex(1L)); Assertions.assertEquals(result, "OK"); Thread.sleep(3000); @@ -152,7 +153,7 @@ public void testSetExNxAsp() { @Test public void testDelAsp() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b"); Assertions.assertEquals(result, "OK"); result = String.valueOf(jedis.del(key)); @@ -166,7 +167,7 @@ public void testBatchDelAsp() { for (int i = 0; i < 2; i++) { keys.add(String.valueOf(ThreadLocalRandom.current().nextInt(50000))); } - try (Jedis jedis = new Jedis("127.0.0.1", 6789)) { + try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(keys.get(0), "b"); Assertions.assertEquals(result, "OK"); result = jedis.set(keys.get(1), "b"); From e3090530dbc0f9ad6e949e66c45a163ac7f5226a Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 17:56:29 +0800 Subject: [PATCH 22/39] optimize: update benchmark report --- README.md | 147 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index b373c21..167f0ef 100644 --- a/README.md +++ b/README.md @@ -3,79 +3,94 @@ High-performance Aerospike proxy for the Redis protocol ### Performance Test Report aerospike 3.x 2c4g redispike-proxy 2c4g: -`./redis-benchmark -h xxxx -p 6379 -n 2000000 -c 200 -t get` +`./redis-benchmark -h xxxx -p 6379 -n 2000000 -c 180 -t get` ``` -WARNING: Could not fetch server CONFIG ====== GET ====== -2000000 requests completed in 44.94 seconds -200 parallel clients -3 bytes payload -keep alive: 1 -multi-thread: no + 2000000 requests completed in 41.07 seconds + 180 parallel clients + 3 bytes payload + keep alive: 1 + multi-thread: no Latency by percentile distribution: -0.000% <= 1.975 milliseconds (cumulative count 1) -50.000% <= 3.879 milliseconds (cumulative count 1001535) -75.000% <= 4.919 milliseconds (cumulative count 1501029) -87.500% <= 5.999 milliseconds (cumulative count 1750484) -93.750% <= 7.247 milliseconds (cumulative count 1875200) -96.875% <= 8.599 milliseconds (cumulative count 1937780) -98.438% <= 10.071 milliseconds (cumulative count 1968821) -99.219% <= 12.023 milliseconds (cumulative count 1984401) -99.609% <= 13.967 milliseconds (cumulative count 1992202) -99.805% <= 16.071 milliseconds (cumulative count 1996100) -99.902% <= 19.199 milliseconds (cumulative count 1998053) -99.951% <= 22.271 milliseconds (cumulative count 1999027) -99.976% <= 24.847 milliseconds (cumulative count 1999515) -99.988% <= 26.831 milliseconds (cumulative count 1999756) -99.994% <= 30.527 milliseconds (cumulative count 1999879) -99.997% <= 31.231 milliseconds (cumulative count 1999942) -99.998% <= 31.535 milliseconds (cumulative count 1999971) -99.999% <= 31.663 milliseconds (cumulative count 1999988) -100.000% <= 31.743 milliseconds (cumulative count 1999993) -100.000% <= 31.807 milliseconds (cumulative count 1999997) -100.000% <= 31.871 milliseconds (cumulative count 1999999) -100.000% <= 31.919 milliseconds (cumulative count 2000000) -100.000% <= 31.919 milliseconds (cumulative count 2000000) +0.000% <= 1.167 milliseconds (cumulative count 1) +50.000% <= 3.215 milliseconds (cumulative count 1002779) +75.000% <= 4.287 milliseconds (cumulative count 1500341) +87.500% <= 5.327 milliseconds (cumulative count 1750471) +93.750% <= 6.487 milliseconds (cumulative count 1875060) +96.875% <= 7.727 milliseconds (cumulative count 1937519) +98.438% <= 9.039 milliseconds (cumulative count 1968840) +99.219% <= 10.335 milliseconds (cumulative count 1984379) +99.609% <= 11.959 milliseconds (cumulative count 1992219) +99.805% <= 13.559 milliseconds (cumulative count 1996101) +99.902% <= 15.215 milliseconds (cumulative count 1998049) +99.951% <= 16.943 milliseconds (cumulative count 1999028) +99.976% <= 19.775 milliseconds (cumulative count 1999512) +99.988% <= 22.575 milliseconds (cumulative count 1999756) +99.994% <= 40.511 milliseconds (cumulative count 1999878) +99.997% <= 42.431 milliseconds (cumulative count 1999939) +99.998% <= 49.663 milliseconds (cumulative count 1999971) +99.999% <= 50.047 milliseconds (cumulative count 1999985) +100.000% <= 50.239 milliseconds (cumulative count 1999993) +100.000% <= 50.367 milliseconds (cumulative count 1999997) +100.000% <= 50.495 milliseconds (cumulative count 1999999) +100.000% <= 52.415 milliseconds (cumulative count 2000000) +100.000% <= 52.415 milliseconds (cumulative count 2000000) Cumulative distribution of latencies: 0.000% <= 0.103 milliseconds (cumulative count 0) -0.001% <= 2.007 milliseconds (cumulative count 10) -0.051% <= 2.103 milliseconds (cumulative count 1012) -22.646% <= 3.103 milliseconds (cumulative count 452915) -56.697% <= 4.103 milliseconds (cumulative count 1133935) -78.001% <= 5.103 milliseconds (cumulative count 1560018) -88.276% <= 6.103 milliseconds (cumulative count 1765529) -93.275% <= 7.103 milliseconds (cumulative count 1865499) -95.983% <= 8.103 milliseconds (cumulative count 1919661) -97.593% <= 9.103 milliseconds (cumulative count 1951867) -98.460% <= 10.103 milliseconds (cumulative count 1969205) -98.949% <= 11.103 milliseconds (cumulative count 1978987) -99.238% <= 12.103 milliseconds (cumulative count 1984763) -99.451% <= 13.103 milliseconds (cumulative count 1989027) -99.629% <= 14.103 milliseconds (cumulative count 1992578) -99.732% <= 15.103 milliseconds (cumulative count 1994648) -99.808% <= 16.103 milliseconds (cumulative count 1996153) -99.853% <= 17.103 milliseconds (cumulative count 1997051) -99.878% <= 18.111 milliseconds (cumulative count 1997563) -99.899% <= 19.103 milliseconds (cumulative count 1997985) -99.918% <= 20.111 milliseconds (cumulative count 1998363) -99.936% <= 21.103 milliseconds (cumulative count 1998710) -99.949% <= 22.111 milliseconds (cumulative count 1998981) -99.962% <= 23.103 milliseconds (cumulative count 1999237) -99.969% <= 24.111 milliseconds (cumulative count 1999375) -99.979% <= 25.103 milliseconds (cumulative count 1999573) -99.984% <= 26.111 milliseconds (cumulative count 1999674) -99.990% <= 27.103 milliseconds (cumulative count 1999795) -99.991% <= 28.111 milliseconds (cumulative count 1999828) -99.993% <= 29.103 milliseconds (cumulative count 1999854) -99.993% <= 30.111 milliseconds (cumulative count 1999862) -99.997% <= 31.103 milliseconds (cumulative count 1999932) -100.000% <= 32.111 milliseconds (cumulative count 2000000) +0.002% <= 1.207 milliseconds (cumulative count 35) +0.063% <= 1.303 milliseconds (cumulative count 1252) +0.312% <= 1.407 milliseconds (cumulative count 6240) +0.802% <= 1.503 milliseconds (cumulative count 16041) +1.724% <= 1.607 milliseconds (cumulative count 34486) +2.999% <= 1.703 milliseconds (cumulative count 59979) +4.846% <= 1.807 milliseconds (cumulative count 96912) +6.978% <= 1.903 milliseconds (cumulative count 139552) +9.776% <= 2.007 milliseconds (cumulative count 195523) +12.656% <= 2.103 milliseconds (cumulative count 253115) +46.802% <= 3.103 milliseconds (cumulative count 936044) +71.720% <= 4.103 milliseconds (cumulative count 1434409) +85.607% <= 5.103 milliseconds (cumulative count 1712133) +92.227% <= 6.103 milliseconds (cumulative count 1844535) +95.630% <= 7.103 milliseconds (cumulative count 1912607) +97.444% <= 8.103 milliseconds (cumulative count 1948873) +98.495% <= 9.103 milliseconds (cumulative count 1969899) +99.116% <= 10.103 milliseconds (cumulative count 1982314) +99.456% <= 11.103 milliseconds (cumulative count 1989124) +99.635% <= 12.103 milliseconds (cumulative count 1992693) +99.761% <= 13.103 milliseconds (cumulative count 1995219) +99.846% <= 14.103 milliseconds (cumulative count 1996921) +99.898% <= 15.103 milliseconds (cumulative count 1997959) +99.931% <= 16.103 milliseconds (cumulative count 1998627) +99.954% <= 17.103 milliseconds (cumulative count 1999076) +99.966% <= 18.111 milliseconds (cumulative count 1999324) +99.972% <= 19.103 milliseconds (cumulative count 1999447) +99.977% <= 20.111 milliseconds (cumulative count 1999541) +99.981% <= 21.103 milliseconds (cumulative count 1999617) +99.985% <= 22.111 milliseconds (cumulative count 1999698) +99.989% <= 23.103 milliseconds (cumulative count 1999778) +99.990% <= 24.111 milliseconds (cumulative count 1999791) +99.990% <= 25.103 milliseconds (cumulative count 1999799) +99.991% <= 26.111 milliseconds (cumulative count 1999820) +99.991% <= 30.111 milliseconds (cumulative count 1999827) +99.991% <= 31.103 milliseconds (cumulative count 1999828) +99.992% <= 39.103 milliseconds (cumulative count 1999842) +99.993% <= 40.127 milliseconds (cumulative count 1999856) +99.995% <= 41.119 milliseconds (cumulative count 1999899) +99.996% <= 42.111 milliseconds (cumulative count 1999930) +99.997% <= 43.103 milliseconds (cumulative count 1999944) +99.997% <= 44.127 milliseconds (cumulative count 1999949) +99.998% <= 45.119 milliseconds (cumulative count 1999951) +99.998% <= 48.127 milliseconds (cumulative count 1999953) +99.998% <= 49.119 milliseconds (cumulative count 1999956) +99.999% <= 50.111 milliseconds (cumulative count 1999988) +100.000% <= 51.103 milliseconds (cumulative count 1999999) +100.000% <= 53.119 milliseconds (cumulative count 2000000) Summary: -throughput summary: 44501.80 requests per second -latency summary (msec): -avg min p50 p95 p99 max -4.337 1.968 3.879 7.679 11.255 31.919 + throughput summary: 48698.53 requests per second + latency summary (msec): + avg min p50 p95 p99 max + 3.628 1.160 3.215 6.871 9.871 52.415 ``` \ No newline at end of file From faa96312de5263c9cab8c9a66ab40e514feb4d59 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 18:20:58 +0800 Subject: [PATCH 23/39] feature: support hdel protocol --- .../protocol/RedisCommandDecoder.java | 3 + .../protocol/RedisCommandHandler.java | 48 +++++++++++++ .../protocol/request/HDelRequest.java | 70 +++++++++++++++++++ .../java/icu/funkye/redispike/ServerTest.java | 7 +- 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index 3912768..2391481 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import com.alipay.remoting.CommandDecoder; +import icu.funkye.redispike.protocol.request.HDelRequest; import icu.funkye.redispike.protocol.request.HSetRequest; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -58,6 +59,8 @@ private RedisRequest convert2RedisRequest(List params) { LOGGER.debug("cmd: {}", params); } switch (cmd) { + case "hdel": + return new HDelRequest(params); case "get": return new GetRequest(params.get(1)); case "command": diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index 7b6a0ec..9831429 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -19,6 +19,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -44,6 +45,7 @@ import icu.funkye.redispike.protocol.request.CommandRequest; import icu.funkye.redispike.protocol.request.DelRequest; import icu.funkye.redispike.protocol.request.GetRequest; +import icu.funkye.redispike.protocol.request.HDelRequest; import icu.funkye.redispike.protocol.request.HSetRequest; import icu.funkye.redispike.protocol.request.SetRequest; import icu.funkye.redispike.protocol.request.conts.Operate; @@ -64,6 +66,52 @@ public void handleCommand(RemotingContext ctx, Object msg) { if(logger.isDebugEnabled()){ logger.debug("redisRequest:{}", redisRequest); } + if(redisRequest instanceof HDelRequest){ + HDelRequest request = (HDelRequest)redisRequest; + Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); + client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { + @Override public void onSuccess(Key key, Record record) { + Map map = record.bins; + for (String field : ((HDelRequest)redisRequest).getFields()) { + map.remove(field); + } + if (map.isEmpty()) { + client.delete(AeroSpikeClientFactory.eventLoops.next(), new DeleteListener() { + @Override public void onSuccess(Key key, boolean b) { + request.setResponse(String.valueOf(request.getFields().size()) + .getBytes(StandardCharsets.UTF_8)); + ctx.writeAndFlush(redisRequest.getResponse()); + } + + @Override public void onFailure(AerospikeException exception) { + logger.error(exception.getMessage(), exception); + ctx.writeAndFlush(redisRequest.getResponse()); + } + }, client.getWritePolicyDefault(), key); + } else { + List newBins = new ArrayList<>(); + map.forEach((k, v) -> newBins.add(new Bin(k, v))); + client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { + @Override public void onSuccess(Key key) { + request.setResponse(String.valueOf(request.getFields().size()) + .getBytes(StandardCharsets.UTF_8)); + ctx.writeAndFlush(redisRequest.getResponse()); + } + + @Override public void onFailure(AerospikeException exception) { + logger.error(exception.getMessage(), exception); + ctx.writeAndFlush(redisRequest.getResponse()); + } + }, client.getWritePolicyDefault(), key, newBins.toArray(new Bin[0])); + } + } + + @Override public void onFailure(AerospikeException exception) { + logger.error(exception.getMessage(), exception); + ctx.writeAndFlush(redisRequest.getResponse()); + } + },client.getReadPolicyDefault(),key); + } if(redisRequest instanceof HSetRequest){ HSetRequest request = (HSetRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java new file mode 100644 index 0000000..9e76c2e --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icu.funkye.redispike.protocol.request; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import icu.funkye.redispike.protocol.RedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.IntegerResponse; + +public class HDelRequest implements RedisRequest { + + String key; + + Set fields; + + IntegerResponse response = new IntegerResponse(); + + public HDelRequest(List params) { + this.key = params.remove(1); + this.fields = new HashSet<>(params); + } + + @Override + public void setResponse(byte[] data) { + this.response.setData(data); + } + + @Override + public RedisResponse getResponse() { + return response; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Set getFields() { + return fields; + } + + public void setFields(Set fields) { + this.fields = fields; + } + + public void setResponse(IntegerResponse response) { + this.response = response; + } +} diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index b25d1a0..00fc934 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -52,22 +52,27 @@ public static void init() throws ParseException { } @Test - public void testhHset() { + public void testhHash() { String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { Long result = jedis.hset(key.getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), "c".getBytes(StandardCharsets.UTF_8)); Assertions.assertEquals(result, 1); + result = jedis.hdel(key, "b"); + Assertions.assertEquals(result, 1); Map map = new HashMap<>(); map.put("b", "c"); map.put("d", "e"); result = jedis.hset(key, map); Assertions.assertEquals(result, 2); + jedis.hdel(key, map.keySet().toArray(new String[0])); key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 1); result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 0); + result = jedis.del(key); + Assertions.assertEquals(result, 1); } } From 92323097b7f076ff272cc6532b728f7d53c216ed Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 18:23:34 +0800 Subject: [PATCH 24/39] feature: support hdel protocol --- .../protocol/RedisCommandHandler.java | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index 9831429..984b0c9 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -24,7 +24,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import com.aerospike.client.AerospikeException; import com.aerospike.client.Bin; @@ -62,28 +61,31 @@ public class RedisCommandHandler implements CommandHandler { @Override public void handleCommand(RemotingContext ctx, Object msg) { if (msg instanceof RedisRequest) { - RedisRequest redisRequest = (RedisRequest) msg; - if(logger.isDebugEnabled()){ + RedisRequest redisRequest = (RedisRequest)msg; + if (logger.isDebugEnabled()) { logger.debug("redisRequest:{}", redisRequest); } - if(redisRequest instanceof HDelRequest){ + if (redisRequest instanceof HDelRequest) { HDelRequest request = (HDelRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { - @Override public void onSuccess(Key key, Record record) { + @Override + public void onSuccess(Key key, Record record) { Map map = record.bins; for (String field : ((HDelRequest)redisRequest).getFields()) { map.remove(field); } if (map.isEmpty()) { client.delete(AeroSpikeClientFactory.eventLoops.next(), new DeleteListener() { - @Override public void onSuccess(Key key, boolean b) { - request.setResponse(String.valueOf(request.getFields().size()) - .getBytes(StandardCharsets.UTF_8)); + @Override + public void onSuccess(Key key, boolean b) { + request.setResponse( + String.valueOf(request.getFields().size()).getBytes(StandardCharsets.UTF_8)); ctx.writeAndFlush(redisRequest.getResponse()); } - @Override public void onFailure(AerospikeException exception) { + @Override + public void onFailure(AerospikeException exception) { logger.error(exception.getMessage(), exception); ctx.writeAndFlush(redisRequest.getResponse()); } @@ -92,13 +94,15 @@ public void handleCommand(RemotingContext ctx, Object msg) { List newBins = new ArrayList<>(); map.forEach((k, v) -> newBins.add(new Bin(k, v))); client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { - @Override public void onSuccess(Key key) { - request.setResponse(String.valueOf(request.getFields().size()) - .getBytes(StandardCharsets.UTF_8)); + @Override + public void onSuccess(Key key) { + request.setResponse( + String.valueOf(request.getFields().size()).getBytes(StandardCharsets.UTF_8)); ctx.writeAndFlush(redisRequest.getResponse()); } - @Override public void onFailure(AerospikeException exception) { + @Override + public void onFailure(AerospikeException exception) { logger.error(exception.getMessage(), exception); ctx.writeAndFlush(redisRequest.getResponse()); } @@ -106,41 +110,43 @@ public void handleCommand(RemotingContext ctx, Object msg) { } } - @Override public void onFailure(AerospikeException exception) { + @Override + public void onFailure(AerospikeException exception) { logger.error(exception.getMessage(), exception); ctx.writeAndFlush(redisRequest.getResponse()); } - },client.getReadPolicyDefault(),key); + }, client.getReadPolicyDefault(), key); } - if(redisRequest instanceof HSetRequest){ + if (redisRequest instanceof HSetRequest) { HSetRequest request = (HSetRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); List list = new ArrayList<>(); - request.getKv().forEach((k,v)->{ - list.add(new Bin(k,v)); + request.getKv().forEach((k, v) -> { + list.add(new Bin(k, v)); }); WritePolicy writePolicy; - if(request.getOperate()!=null&&request.getOperate()==Operate.NX){ - writePolicy = new WritePolicy(client.getWritePolicyDefault()); + if (request.getOperate() != null && request.getOperate() == Operate.NX) { + writePolicy = new WritePolicy(client.getWritePolicyDefault()); writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; - }else { + } else { writePolicy = client.getWritePolicyDefault(); } client.put(AeroSpikeClientFactory.eventLoops.next(), new WriteListener() { - @Override public void onSuccess(Key key) { - request.setResponse( - String.valueOf(request.getKv().size()).getBytes(StandardCharsets.UTF_8)); + @Override + public void onSuccess(Key key) { + request.setResponse(String.valueOf(request.getKv().size()).getBytes(StandardCharsets.UTF_8)); ctx.writeAndFlush(redisRequest.getResponse()); } - @Override public void onFailure(AerospikeException ae) { + @Override + public void onFailure(AerospikeException ae) { logger.error(ae.getMessage(), ae); ctx.writeAndFlush(redisRequest.getResponse()); } }, writePolicy, key, list.toArray(new Bin[0])); } if (redisRequest instanceof GetRequest) { - GetRequest getRequest = (GetRequest) redisRequest; + GetRequest getRequest = (GetRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, getRequest.getKey()); client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override @@ -164,7 +170,7 @@ public void onFailure(AerospikeException ae) { }, client.getReadPolicyDefault(), key); } if (redisRequest instanceof SetRequest) { - SetRequest setRequest = (SetRequest) redisRequest; + SetRequest setRequest = (SetRequest)redisRequest; Bin bin = new Bin(setRequest.getKey(), setRequest.getValue()); Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, setRequest.getKey()); WritePolicy writePolicy = null; @@ -173,7 +179,7 @@ public void onFailure(AerospikeException ae) { if (setRequest.getTtlType() == TtlType.EX) { writePolicy.expiration = setRequest.getTtl().intValue(); } else { - writePolicy.expiration = Integer.max((int) (setRequest.getTtl() / 1000), 1); + writePolicy.expiration = Integer.max((int)(setRequest.getTtl() / 1000), 1); } } if (setRequest.getOperate() != null) { @@ -182,8 +188,7 @@ public void onFailure(AerospikeException ae) { } if (setRequest.getOperate() == Operate.NX) { writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; - }else - if (setRequest.getOperate() == Operate.XX) { + } else if (setRequest.getOperate() == Operate.XX) { client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { @@ -237,22 +242,23 @@ public void onFailure(AerospikeException ae) { }, writePolicy, key, bin); } if (redisRequest instanceof CommandRequest) { - CommandRequest commandRequest = (CommandRequest) redisRequest; + CommandRequest commandRequest = (CommandRequest)redisRequest; commandRequest.setResponse("OK".getBytes(StandardCharsets.UTF_8)); ctx.writeAndFlush(redisRequest.getResponse()); } if (redisRequest instanceof DelRequest) { - DelRequest delRequest = (DelRequest) redisRequest; + DelRequest delRequest = (DelRequest)redisRequest; List keys = delRequest.getKey(); - List list = keys.stream().map(key->new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, key)).collect( - Collectors.toList()); + List list = + keys.stream().map(key -> new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, key)) + .collect(Collectors.toList()); CountDownLatch countDownLatch = new CountDownLatch(list.size()); for (Key key : list) { client.delete(AeroSpikeClientFactory.eventLoops.next(), new DeleteListener() { @Override public void onSuccess(Key key, boolean b) { - delRequest.setResponse( - String.valueOf(delRequest.getCount().incrementAndGet()).getBytes(StandardCharsets.UTF_8)); + delRequest.setResponse(String.valueOf(delRequest.getCount().incrementAndGet()) + .getBytes(StandardCharsets.UTF_8)); countDownLatch.countDown(); } From 9d79bfdd9652d4af83b876dc814b289e096f6e58 Mon Sep 17 00:00:00 2001 From: jianbin Date: Sun, 7 Apr 2024 18:24:43 +0800 Subject: [PATCH 25/39] feature: support hdel protocol --- .../java/icu/funkye/redispike/protocol/request/HDelRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java index 9e76c2e..545aeab 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java @@ -34,7 +34,7 @@ public class HDelRequest implements RedisRequest { IntegerResponse response = new IntegerResponse(); public HDelRequest(List params) { - this.key = params.remove(1); + this.key = params.remove(0); this.fields = new HashSet<>(params); } From c5f79f4ba8b8ad8a5f5abce0b81754190c6be6f4 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:02:32 +0800 Subject: [PATCH 26/39] feature: support del protocol --- .../icu/funkye/redispike/protocol/RedisCommandHandler.java | 5 ++--- .../icu/funkye/redispike/protocol/request/HDelRequest.java | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index 984b0c9..dae5a00 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -66,6 +66,7 @@ public void handleCommand(RemotingContext ctx, Object msg) { logger.debug("redisRequest:{}", redisRequest); } if (redisRequest instanceof HDelRequest) { + logger.info("redisRequest:{}", redisRequest); HDelRequest request = (HDelRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @@ -121,9 +122,7 @@ public void onFailure(AerospikeException exception) { HSetRequest request = (HSetRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); List list = new ArrayList<>(); - request.getKv().forEach((k, v) -> { - list.add(new Bin(k, v)); - }); + request.getKv().forEach((k, v) -> list.add(new Bin(k, v))); WritePolicy writePolicy; if (request.getOperate() != null && request.getOperate() == Operate.NX) { writePolicy = new WritePolicy(client.getWritePolicyDefault()); diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java index 545aeab..74d04e1 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java @@ -67,4 +67,9 @@ public void setFields(Set fields) { public void setResponse(IntegerResponse response) { this.response = response; } + + @Override + public String toString() { + return "HDelRequest{" + "key='" + key + '\'' + ", fields=" + fields + ", response=" + response + '}'; + } } From d808145062bdef527a067681548159b86abb7c43 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:06:27 +0800 Subject: [PATCH 27/39] test --- .../icu/funkye/redispike/protocol/RedisCommandHandler.java | 1 - .../icu/funkye/redispike/protocol/request/HDelRequest.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java index dae5a00..0c0128f 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandHandler.java @@ -66,7 +66,6 @@ public void handleCommand(RemotingContext ctx, Object msg) { logger.debug("redisRequest:{}", redisRequest); } if (redisRequest instanceof HDelRequest) { - logger.info("redisRequest:{}", redisRequest); HDelRequest request = (HDelRequest)redisRequest; Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); client.get(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java index 74d04e1..44e6d30 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java @@ -34,7 +34,8 @@ public class HDelRequest implements RedisRequest { IntegerResponse response = new IntegerResponse(); public HDelRequest(List params) { - this.key = params.remove(0); + params.remove(0); + this.key = params.remove(1); this.fields = new HashSet<>(params); } From 99a433796cab8a1a422bb2b18d02bb9fdf81e2c6 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:08:28 +0800 Subject: [PATCH 28/39] test --- .../java/icu/funkye/redispike/protocol/request/HDelRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java index 44e6d30..8d940ff 100644 --- a/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java +++ b/src/main/java/icu/funkye/redispike/protocol/request/HDelRequest.java @@ -35,7 +35,7 @@ public class HDelRequest implements RedisRequest { public HDelRequest(List params) { params.remove(0); - this.key = params.remove(1); + this.key = params.remove(0); this.fields = new HashSet<>(params); } From 5047fa06e30b0c3dae36c94d921b5004f90de1f3 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:11:12 +0800 Subject: [PATCH 29/39] test --- src/test/java/icu/funkye/redispike/ServerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 00fc934..1f7900a 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -65,7 +65,8 @@ public void testhHash() { map.put("d", "e"); result = jedis.hset(key, map); Assertions.assertEquals(result, 2); - jedis.hdel(key, map.keySet().toArray(new String[0])); + result = jedis.hdel(key, map.keySet().toArray(new String[0])); + Assertions.assertEquals(result, 2); key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 1); From b9704e518604007fde86a90799b4979beb3a6593 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:55:09 +0800 Subject: [PATCH 30/39] test --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1cab36..4f86879 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,4 +48,7 @@ jobs: ./mvnw -T 4C clean test - name: "Codecov" if: matrix.java == '8' - uses: codecov/codecov-action@v3.1.4 + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: funky-eyes/redispike-proxy \ No newline at end of file From f43d2264e4e428e12be89ced273fe48fc7b4e1c4 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:57:30 +0800 Subject: [PATCH 31/39] test --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f86879..010bc73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,6 @@ jobs: run: | ./mvnw -T 4C clean test - name: "Codecov" - if: matrix.java == '8' uses: codecov/codecov-action@v4.0.1 with: token: ${{ secrets.CODECOV_TOKEN }} From 74733694f523e5eaf9aae042537bff2741fd0f17 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 20:59:38 +0800 Subject: [PATCH 32/39] test --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 010bc73..4f86879 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,7 @@ jobs: run: | ./mvnw -T 4C clean test - name: "Codecov" + if: matrix.java == '8' uses: codecov/codecov-action@v4.0.1 with: token: ${{ secrets.CODECOV_TOKEN }} From e4f04139c182a26de521fa3219eae63f2423f7c5 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:07:20 +0800 Subject: [PATCH 33/39] test --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f86879..6af5618 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,5 +50,4 @@ jobs: if: matrix.java == '8' uses: codecov/codecov-action@v4.0.1 with: - token: ${{ secrets.CODECOV_TOKEN }} - slug: funky-eyes/redispike-proxy \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From 031d98f75cbfcf8566dc83fdabe549b31c3e7d44 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:11:56 +0800 Subject: [PATCH 34/39] test --- codecov.yml | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/codecov.yml b/codecov.yml index 15e2a70..47656bd 100644 --- a/codecov.yml +++ b/codecov.yml @@ -14,25 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # +flag_management: + individual_flags: + - name: smart-tests + carryforward: true + carryforward_mode: "labels" + statuses: + - type: "project" + - type: "patch" -codecov: - require_ci_to_pass: yes -coverage: - status: - patch: no - project: - default: - threshold: 1% - if_not_found: success - changes: no - precision: 2 - range: "50...100" -ignore: - - ".github/.*" - - ".mvn/.*" - - ".style/.*" - - "*.md" -comment: - layout: "reach,diff,flags,tree" - behavior: default - require_changes: no +cli: + plugins: + pycoverage: + report_type: "json" From 0c65cf0cb09a62e31a890823fcba09c01822e8e0 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:12:54 +0800 Subject: [PATCH 35/39] test --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6af5618..eebe426 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,8 +46,11 @@ jobs: if: matrix.java != '8' run: | ./mvnw -T 4C clean test - - name: "Codecov" + - name: Upload coverage to Codecov if: matrix.java == '8' - uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v4 with: - token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + flags: smart-tests + verbose: true + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From ff6c99c35c46085701784b9ed766f4831c7f42df Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:14:39 +0800 Subject: [PATCH 36/39] test --- .../java/icu/funkye/redispike/ServerTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 1f7900a..1e612ab 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -43,6 +43,8 @@ public class ServerTest { static Logger logger = LoggerFactory.getLogger(ServerTest.class); + private final int RandomValue = Integer.MAX_VALUE; + @BeforeAll public static void init() throws ParseException { server = new Server(); @@ -53,7 +55,7 @@ public static void init() throws ParseException { @Test public void testhHash() { - String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + String key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { Long result = jedis.hset(key.getBytes(StandardCharsets.UTF_8), "b".getBytes(StandardCharsets.UTF_8), "c".getBytes(StandardCharsets.UTF_8)); @@ -67,7 +69,7 @@ public void testhHash() { Assertions.assertEquals(result, 2); result = jedis.hdel(key, map.keySet().toArray(new String[0])); Assertions.assertEquals(result, 2); - key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); result = jedis.hsetnx(key, "f", "g"); Assertions.assertEquals(result, 1); result = jedis.hsetnx(key, "f", "g"); @@ -114,7 +116,7 @@ public void testGetNilAsp() { @Test public void testSetExAsp() { - String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + String key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().ex(1L)); Assertions.assertEquals(result, "OK"); @@ -128,13 +130,13 @@ public void testSetExAsp() { @Test public void testSetNxNilAsp() { - String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + String key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().nx()); Assertions.assertEquals(result, "OK"); result = jedis.set(key, "b", SetParams.setParams().nx()); Assertions.assertNull(result); - key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); result = String.valueOf(jedis.setnx(key, "b")); Assertions.assertEquals(result, "1"); result = String.valueOf(jedis.setnx(key, "b")); @@ -144,7 +146,7 @@ public void testSetNxNilAsp() { @Test public void testSetExNxAsp() { - String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + String key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b", SetParams.setParams().nx().ex(1L)); Assertions.assertEquals(result, "OK"); @@ -158,7 +160,7 @@ public void testSetExNxAsp() { @Test public void testDelAsp() { - String key = String.valueOf(ThreadLocalRandom.current().nextInt(50000)); + String key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue)); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(key, "b"); Assertions.assertEquals(result, "OK"); @@ -171,7 +173,7 @@ public void testDelAsp() { public void testBatchDelAsp() { List keys = new ArrayList<>(); for (int i = 0; i < 2; i++) { - keys.add(String.valueOf(ThreadLocalRandom.current().nextInt(50000))); + keys.add(String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue))); } try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { String result = jedis.set(keys.get(0), "b"); From 3227a92f8bc95145010aca57324b2da009045652 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:18:18 +0800 Subject: [PATCH 37/39] test --- .github/workflows/build.yml | 4 ++-- src/test/java/icu/funkye/redispike/ServerTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eebe426..d4e2fc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,9 +30,9 @@ jobs: java: [ 8, 21 ] steps: - name: "Checkout" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up Java JDK" - uses: actions/setup-java@v3.12.0 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: ${{ matrix.java }} diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 1e612ab..6c0ed0d 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -41,9 +41,9 @@ public class ServerTest { static Server server; static IAerospikeClient aspClient; - static Logger logger = LoggerFactory.getLogger(ServerTest.class); + static Logger logger = LoggerFactory.getLogger(ServerTest.class); - private final int RandomValue = Integer.MAX_VALUE; + private final int RandomValue = Integer.MAX_VALUE; @BeforeAll public static void init() throws ParseException { From fb0b25e1d8f85522c5504ff14226e0a647963400 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:27:21 +0800 Subject: [PATCH 38/39] test --- .github/workflows/build.yml | 7 +------ pom.xml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4e2fc5..2860672 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,14 +38,9 @@ jobs: java-version: ${{ matrix.java }} - name: "Print maven version" run: ./mvnw -version - - name: "Test, Check style, Check PMD, Check license with Maven and Java8" - if: matrix.java == '8' + - name: "Test, Check style, Check PMD, Check license with Maven and Java" run: | ./mvnw -T 4C clean test && sh ./tools/check_format.sh - - name: "Test with Maven and Java${{ matrix.java }}" - if: matrix.java != '8' - run: | - ./mvnw -T 4C clean test - name: Upload coverage to Codecov if: matrix.java == '8' uses: codecov/codecov-action@v4 diff --git a/pom.xml b/pom.xml index c7861f8..0a9fe65 100644 --- a/pom.xml +++ b/pom.xml @@ -207,6 +207,26 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + \ No newline at end of file From f63b630f2b12bb5a8362297af932fbb1463771f9 Mon Sep 17 00:00:00 2001 From: funky-eyes Date: Sun, 7 Apr 2024 21:30:32 +0800 Subject: [PATCH 39/39] test --- .github/workflows/build.yml | 9 +++------ codecov.yml | 33 +++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2860672..de947e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,11 +41,8 @@ jobs: - name: "Test, Check style, Check PMD, Check license with Maven and Java" run: | ./mvnw -T 4C clean test && sh ./tools/check_format.sh - - name: Upload coverage to Codecov + - name: "Codecov" if: matrix.java == '8' - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v4.0.1 with: - flags: smart-tests - verbose: true - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/codecov.yml b/codecov.yml index 47656bd..a9a1762 100644 --- a/codecov.yml +++ b/codecov.yml @@ -14,16 +14,25 @@ # See the License for the specific language governing permissions and # limitations under the License. # -flag_management: - individual_flags: - - name: smart-tests - carryforward: true - carryforward_mode: "labels" - statuses: - - type: "project" - - type: "patch" -cli: - plugins: - pycoverage: - report_type: "json" +codecov: + require_ci_to_pass: yes +coverage: + status: + patch: no + project: + default: + threshold: 1% + if_not_found: success + changes: no + precision: 2 + range: "50...100" +ignore: + - ".github/.*" + - ".mvn/.*" + - ".style/.*" + - "*.md" +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: no