From 0ba075e72f01f6de04e88b509ccc660a54d29274 Mon Sep 17 00:00:00 2001 From: jianbin Date: Tue, 16 Apr 2024 14:42:40 +0800 Subject: [PATCH 1/3] feature: support hincrby protocol --- .../handler/RedisCommandHandler.java | 3 + .../process/impl/HIncrbyRequestProcessor.java | 70 +++++++++++++++++++ .../protocol/RedisCommandDecoder.java | 3 + .../protocol/request/HIncrbyRequest.java | 66 +++++++++++++++++ .../java/icu/funkye/redispike/ServerTest.java | 5 ++ 5 files changed, 147 insertions(+) create mode 100644 src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/HIncrbyRequest.java diff --git a/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java index 698d244..feb91f5 100644 --- a/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java @@ -33,6 +33,7 @@ import icu.funkye.redispike.handler.process.impl.HExistsRequestProcessor; import icu.funkye.redispike.handler.process.impl.HGetAllRequestProcessor; import icu.funkye.redispike.handler.process.impl.HGetRequestProcessor; +import icu.funkye.redispike.handler.process.impl.HIncrbyRequestProcessor; import icu.funkye.redispike.handler.process.impl.HMgetRequestProcessor; import icu.funkye.redispike.handler.process.impl.HSetRequestProcessor; import icu.funkye.redispike.handler.process.impl.HValsRequestProcessor; @@ -94,6 +95,8 @@ public RedisCommandHandler() { processorMap.put(hExistsRequestProcessor.getCmdCode().value(), hExistsRequestProcessor); HValsRequestProcessor hValsRequestProcessor = new HValsRequestProcessor(); processorMap.put(hValsRequestProcessor.getCmdCode().value(), hValsRequestProcessor); + HIncrbyRequestProcessor hIncrbyRequestProcessor = new HIncrbyRequestProcessor(); + processorMap.put(hIncrbyRequestProcessor.getCmdCode().value(), hIncrbyRequestProcessor); } @Override diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java new file mode 100644 index 0000000..70c7b76 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.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.handler.process.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.aerospike.client.AerospikeException; +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import com.aerospike.client.Operation; +import com.aerospike.client.Record; +import com.aerospike.client.listener.RecordListener; +import com.aerospike.client.listener.WriteListener; +import com.aerospike.client.policy.RecordExistsAction; +import com.aerospike.client.policy.WritePolicy; +import com.alipay.remoting.RemotingContext; + +import icu.funkye.redispike.factory.AeroSpikeClientFactory; +import icu.funkye.redispike.handler.process.AbstractRedisRequestProcessor; +import icu.funkye.redispike.protocol.RedisRequestCommandCode; +import icu.funkye.redispike.protocol.request.HIncrbyRequest; +import icu.funkye.redispike.protocol.request.HSetRequest; +import icu.funkye.redispike.protocol.request.conts.Operate; +import icu.funkye.redispike.util.IntegerUtils; + +public class HIncrbyRequestProcessor extends AbstractRedisRequestProcessor { + WritePolicy defaultWritePolicy; + + public HIncrbyRequestProcessor() { + this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HIncrbyRequest.class.hashCode())); + this.defaultWritePolicy = client.getWritePolicyDefault(); + this.defaultWritePolicy.sendKey = true; + } + + @Override + public void handle(RemotingContext ctx, HIncrbyRequest request) { + Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); + String value = request.getValue(); + Bin bin = new Bin(request.getField(), value.contains(".") ? Double.parseDouble(value) : Long.parseLong(request + .getValue())); + client.operate(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { + @Override + public void onSuccess(Key key, Record record) { + request.setResponse(record.getString(request.getField())); + write(ctx, request); + } + + @Override + public void onFailure(AerospikeException exception) { + logger.error(exception.getMessage(), exception); + write(ctx, request); + } + }, defaultWritePolicy, key, Operation.add(bin), Operation.get(request.getField())); + } +} diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index a29f24e..7aede89 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -26,6 +26,7 @@ import icu.funkye.redispike.protocol.request.HExistsRequest; import icu.funkye.redispike.protocol.request.HGetAllRequest; import icu.funkye.redispike.protocol.request.HGetRequest; +import icu.funkye.redispike.protocol.request.HIncrbyRequest; import icu.funkye.redispike.protocol.request.HMgetRequest; import icu.funkye.redispike.protocol.request.HSetRequest; import icu.funkye.redispike.protocol.request.HValsRequest; @@ -115,6 +116,8 @@ private AbstractRedisRequest convert2RedisRequest(List params, boolea return new DelRequest(params, flush); case "hget": return new HGetRequest(params.get(1), params.size() > 2 ? params.get(2) : null, flush); + case "hincrby": + return new HIncrbyRequest(params.get(1), params.get(2), params.get(3), flush); case "hgetall": return new HGetAllRequest(params.get(1), flush); case "hvals": diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyRequest.java new file mode 100644 index 0000000..9dde07b --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyRequest.java @@ -0,0 +1,66 @@ +/* + * 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 icu.funkye.redispike.protocol.AbstractRedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.IntegerResponse; + +public class HIncrbyRequest extends AbstractRedisRequest { + + final String key; + + final String field; + + final String value; + + IntegerResponse response = new IntegerResponse(); + + public HIncrbyRequest(String key, String field, String value, boolean flush) { + this.flush = flush; + this.key = key; + this.value = value; + this.field = field; + } + + public String getKey() { + return key; + } + + @Override + public void setResponse(String data) { + this.response.setData(data); + } + + @Override + public RedisResponse getResponse() { + return response; + } + + public String getField() { + return field; + } + + public String getValue() { + return value; + } + + 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 f4a05d4..53a820f 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -187,6 +187,11 @@ public void testhHash() { Assertions.assertEquals(result, 1); list = jedis.hvals(key); Assertions.assertEquals(list.size(), 0); + result = jedis.hincrBy(key, "d", 1); + Assertions.assertEquals(result, 1); + result = jedis.hincrBy(key, "d", 5); + Assertions.assertEquals(result, 6); + jedis.del(key); } } From 13dcf0a13df5779860e45dbba17f3e61bb224c4a Mon Sep 17 00:00:00 2001 From: jianbin Date: Wed, 17 Apr 2024 10:03:18 +0800 Subject: [PATCH 2/3] feature: support hincrby protocol --- .../process/impl/HGetRequestProcessor.java | 6 +++--- .../process/impl/HIncrbyRequestProcessor.java | 16 ++++++++++++---- .../process/impl/HSetRequestProcessor.java | 3 ++- .../java/icu/funkye/redispike/ServerTest.java | 7 +++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HGetRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HGetRequestProcessor.java index 3419dc7..7acda0a 100644 --- a/src/main/java/icu/funkye/redispike/handler/process/impl/HGetRequestProcessor.java +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HGetRequestProcessor.java @@ -49,9 +49,9 @@ public void onSuccess(Key key, Record record) { write(ctx, request); return; } - String value = record.getString(request.getField()); - if (StringUtil.isNotBlank(value)) { - request.setResponse(value); + Object value = record.getValue(request.getField()); + if (value != null) { + request.setResponse(value.toString()); } write(ctx, request); } diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java index 70c7b76..2906076 100644 --- a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java @@ -50,13 +50,20 @@ public HIncrbyRequestProcessor() { @Override public void handle(RemotingContext ctx, HIncrbyRequest request) { Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); - String value = request.getValue(); - Bin bin = new Bin(request.getField(), value.contains(".") ? Double.parseDouble(value) : Long.parseLong(request - .getValue())); + Object value; + if (request.getValue().contains(".")) { + value = Double.parseDouble(request.getValue()); + } else { + value = Long.parseLong(request.getValue()); + } + Bin bin = new Bin(request.getField(), value); client.operate(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { - request.setResponse(record.getString(request.getField())); + Object value = record.getValue(request.getField()); + if (value != null) { + request.setResponse(value.toString()); + } write(ctx, request); } @@ -67,4 +74,5 @@ public void onFailure(AerospikeException exception) { } }, defaultWritePolicy, key, Operation.add(bin), Operation.get(request.getField())); } + } diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java index c049b96..afc9b38 100644 --- a/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java @@ -25,6 +25,7 @@ import com.aerospike.client.policy.RecordExistsAction; import com.aerospike.client.policy.WritePolicy; import com.alipay.remoting.RemotingContext; +import com.alipay.remoting.util.StringUtils; import icu.funkye.redispike.factory.AeroSpikeClientFactory; import icu.funkye.redispike.handler.process.AbstractRedisRequestProcessor; import icu.funkye.redispike.protocol.RedisRequestCommandCode; @@ -45,7 +46,7 @@ public HSetRequestProcessor() { public void handle(RemotingContext ctx, HSetRequest request) { 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, StringUtils.isNumeric(v)?Long.parseLong(v):v))); WritePolicy writePolicy; if (request.getOperate() != null && request.getOperate() == Operate.NX) { writePolicy = new WritePolicy(defaultWritePolicy); diff --git a/src/test/java/icu/funkye/redispike/ServerTest.java b/src/test/java/icu/funkye/redispike/ServerTest.java index 53a820f..29a06a3 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -187,9 +187,12 @@ public void testhHash() { Assertions.assertEquals(result, 1); list = jedis.hvals(key); Assertions.assertEquals(list.size(), 0); - result = jedis.hincrBy(key, "d", 1); + result = jedis.hset(key, "t", "0"); Assertions.assertEquals(result, 1); - result = jedis.hincrBy(key, "d", 5); + Assertions.assertEquals(jedis.hget(key, "t"), "0"); + result = jedis.hincrBy(key, "t", 1); + Assertions.assertEquals(result, 1); + result = jedis.hincrBy(key, "t", 5); Assertions.assertEquals(result, 6); jedis.del(key); } From e6f8caf563a3c5d52f43354148bd9fd67229226a Mon Sep 17 00:00:00 2001 From: jianbin Date: Wed, 17 Apr 2024 14:14:41 +0800 Subject: [PATCH 3/3] feature: support hincrbyfloat protocol --- .../handler/RedisCommandHandler.java | 3 + .../process/impl/HIncrbyRequestProcessor.java | 8 +-- .../impl/HIncrbyfloatRequestProcessor.java | 66 ++++++++++++++++++ .../process/impl/HSetRequestProcessor.java | 12 +++- .../protocol/RedisCommandDecoder.java | 3 + .../protocol/request/HIncrbyfloatRequest.java | 67 +++++++++++++++++++ .../java/icu/funkye/redispike/ServerTest.java | 7 ++ 7 files changed, 158 insertions(+), 8 deletions(-) create mode 100644 src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyfloatRequestProcessor.java create mode 100644 src/main/java/icu/funkye/redispike/protocol/request/HIncrbyfloatRequest.java diff --git a/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java b/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java index feb91f5..1431a7d 100644 --- a/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java +++ b/src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java @@ -34,6 +34,7 @@ import icu.funkye.redispike.handler.process.impl.HGetAllRequestProcessor; import icu.funkye.redispike.handler.process.impl.HGetRequestProcessor; import icu.funkye.redispike.handler.process.impl.HIncrbyRequestProcessor; +import icu.funkye.redispike.handler.process.impl.HIncrbyfloatRequestProcessor; import icu.funkye.redispike.handler.process.impl.HMgetRequestProcessor; import icu.funkye.redispike.handler.process.impl.HSetRequestProcessor; import icu.funkye.redispike.handler.process.impl.HValsRequestProcessor; @@ -97,6 +98,8 @@ public RedisCommandHandler() { processorMap.put(hValsRequestProcessor.getCmdCode().value(), hValsRequestProcessor); HIncrbyRequestProcessor hIncrbyRequestProcessor = new HIncrbyRequestProcessor(); processorMap.put(hIncrbyRequestProcessor.getCmdCode().value(), hIncrbyRequestProcessor); + HIncrbyfloatRequestProcessor hIncrbyfloatRequestProcessor = new HIncrbyfloatRequestProcessor(); + processorMap.put(hIncrbyfloatRequestProcessor.getCmdCode().value(), hIncrbyfloatRequestProcessor); } @Override diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java index 2906076..b1bf313 100644 --- a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyRequestProcessor.java @@ -50,13 +50,7 @@ public HIncrbyRequestProcessor() { @Override public void handle(RemotingContext ctx, HIncrbyRequest request) { Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); - Object value; - if (request.getValue().contains(".")) { - value = Double.parseDouble(request.getValue()); - } else { - value = Long.parseLong(request.getValue()); - } - Bin bin = new Bin(request.getField(), value); + Bin bin = new Bin(request.getField(), Long.parseLong(request.getValue())); client.operate(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { @Override public void onSuccess(Key key, Record record) { diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyfloatRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyfloatRequestProcessor.java new file mode 100644 index 0000000..7f28da4 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HIncrbyfloatRequestProcessor.java @@ -0,0 +1,66 @@ +/* + * 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.handler.process.impl; + +import com.aerospike.client.AerospikeException; +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import com.aerospike.client.Operation; +import com.aerospike.client.Record; +import com.aerospike.client.listener.RecordListener; +import com.aerospike.client.policy.WritePolicy; +import com.alipay.remoting.RemotingContext; + +import icu.funkye.redispike.factory.AeroSpikeClientFactory; +import icu.funkye.redispike.handler.process.AbstractRedisRequestProcessor; +import icu.funkye.redispike.protocol.RedisRequestCommandCode; +import icu.funkye.redispike.protocol.request.HIncrbyRequest; +import icu.funkye.redispike.protocol.request.HIncrbyfloatRequest; +import icu.funkye.redispike.util.IntegerUtils; + +public class HIncrbyfloatRequestProcessor extends AbstractRedisRequestProcessor { + WritePolicy defaultWritePolicy; + + public HIncrbyfloatRequestProcessor() { + this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HIncrbyfloatRequest.class.hashCode())); + this.defaultWritePolicy = client.getWritePolicyDefault(); + this.defaultWritePolicy.sendKey = true; + } + + @Override + public void handle(RemotingContext ctx, HIncrbyfloatRequest request) { + Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); + Bin bin = new Bin(request.getField(), Double.parseDouble(request.getValue())); + client.operate(AeroSpikeClientFactory.eventLoops.next(), new RecordListener() { + @Override + public void onSuccess(Key key, Record record) { + Object value = record.getValue(request.getField()); + if (value != null) { + request.setResponse(String.valueOf(value)); + } + write(ctx, request); + } + + @Override + public void onFailure(AerospikeException exception) { + logger.error(exception.getMessage(), exception); + write(ctx, request); + } + }, defaultWritePolicy, key, Operation.add(bin), Operation.get(request.getField())); + } + +} diff --git a/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java b/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java index afc9b38..1bffd73 100644 --- a/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java +++ b/src/main/java/icu/funkye/redispike/handler/process/impl/HSetRequestProcessor.java @@ -46,7 +46,17 @@ public HSetRequestProcessor() { public void handle(RemotingContext ctx, HSetRequest request) { Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey()); List list = new ArrayList<>(); - request.getKv().forEach((k, v) -> list.add(new Bin(k, StringUtils.isNumeric(v)?Long.parseLong(v):v))); + request.getKv().forEach((k, v) -> { + Object value; + if (StringUtils.isNumeric(v)) { + value = Long.parseLong(v); + } else if (v.matches("-?\\d+(\\.\\d+)?")) { + value = Double.parseDouble(v); + } else { + value = v; + } + list.add(new Bin(k, value)); + }); WritePolicy writePolicy; if (request.getOperate() != null && request.getOperate() == Operate.NX) { writePolicy = new WritePolicy(defaultWritePolicy); diff --git a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java index 7aede89..8c515dd 100644 --- a/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java +++ b/src/main/java/icu/funkye/redispike/protocol/RedisCommandDecoder.java @@ -27,6 +27,7 @@ import icu.funkye.redispike.protocol.request.HGetAllRequest; import icu.funkye.redispike.protocol.request.HGetRequest; import icu.funkye.redispike.protocol.request.HIncrbyRequest; +import icu.funkye.redispike.protocol.request.HIncrbyfloatRequest; import icu.funkye.redispike.protocol.request.HMgetRequest; import icu.funkye.redispike.protocol.request.HSetRequest; import icu.funkye.redispike.protocol.request.HValsRequest; @@ -118,6 +119,8 @@ private AbstractRedisRequest convert2RedisRequest(List params, boolea return new HGetRequest(params.get(1), params.size() > 2 ? params.get(2) : null, flush); case "hincrby": return new HIncrbyRequest(params.get(1), params.get(2), params.get(3), flush); + case "hincrbyfloat": + return new HIncrbyfloatRequest(params.get(1), params.get(2), params.get(3), flush); case "hgetall": return new HGetAllRequest(params.get(1), flush); case "hvals": diff --git a/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyfloatRequest.java b/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyfloatRequest.java new file mode 100644 index 0000000..e2668d0 --- /dev/null +++ b/src/main/java/icu/funkye/redispike/protocol/request/HIncrbyfloatRequest.java @@ -0,0 +1,67 @@ +/* + * 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 icu.funkye.redispike.protocol.AbstractRedisRequest; +import icu.funkye.redispike.protocol.RedisResponse; +import icu.funkye.redispike.protocol.response.BulkResponse; +import icu.funkye.redispike.protocol.response.IntegerResponse; + +public class HIncrbyfloatRequest extends AbstractRedisRequest { + + final String key; + + final String field; + + final String value; + + BulkResponse response = new BulkResponse(); + + public HIncrbyfloatRequest(String key, String field, String value, boolean flush) { + this.flush = flush; + this.key = key; + this.value = value; + this.field = field; + } + + public String getKey() { + return key; + } + + @Override + public void setResponse(String data) { + this.response.setData(data); + } + + @Override + public RedisResponse getResponse() { + return response; + } + + public String getField() { + return field; + } + + public String getValue() { + return value; + } + + public void setResponse(BulkResponse 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 29a06a3..c2dcf35 100644 --- a/src/test/java/icu/funkye/redispike/ServerTest.java +++ b/src/test/java/icu/funkye/redispike/ServerTest.java @@ -194,6 +194,13 @@ public void testhHash() { Assertions.assertEquals(result, 1); result = jedis.hincrBy(key, "t", 5); Assertions.assertEquals(result, 6); + result = jedis.hincrBy(key, "t", -1); + Assertions.assertEquals(result, 5); + jedis.del(key); + result = jedis.hset(key, "t", "0.0"); + Assertions.assertEquals(result, 1); + Double res = jedis.hincrByFloat(key, "t", 5.1); + Assertions.assertEquals(res, 5.1); jedis.del(key); } }