Skip to content

Commit

Permalink
feature: support hlen protocol (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes committed Apr 18, 2024
1 parent c66b872 commit 192c9cf
Show file tree
Hide file tree
Showing 37 changed files with 219 additions and 111 deletions.
36 changes: 18 additions & 18 deletions src/main/java/icu/funkye/redispike/handler/RedisCommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,36 @@
*/
package icu.funkye.redispike.handler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import com.alipay.remoting.CommandCode;
import com.alipay.remoting.CommandHandler;
import com.alipay.remoting.RemotingContext;
import com.alipay.remoting.RemotingProcessor;
import icu.funkye.redispike.handler.process.impl.GetRequestProcessor;
import icu.funkye.redispike.handler.process.impl.HDelRequestProcessor;
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.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;
import icu.funkye.redispike.handler.process.impl.hash.HDelRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HExistsRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HGetAllRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HGetRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HIncrbyRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HIncrbyfloatRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HLenRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HMgetRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HSetRequestProcessor;
import icu.funkye.redispike.handler.process.impl.hash.HValsRequestProcessor;
import icu.funkye.redispike.handler.process.impl.KeysRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SCardRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SPopRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SRandmemberRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SRemRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SCardRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SPopRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SRandmemberRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SRemRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SetRequestProcessor;
import icu.funkye.redispike.handler.process.impl.CommandRequestProcessor;
import icu.funkye.redispike.handler.process.impl.DelRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SAddRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SMembersRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SAddRequestProcessor;
import icu.funkye.redispike.handler.process.impl.set.SMembersRequestProcessor;
import icu.funkye.redispike.protocol.RedisRequest;
import icu.funkye.redispike.protocol.response.BulkResponse;
import org.slf4j.Logger;
Expand Down Expand Up @@ -100,6 +98,8 @@ public RedisCommandHandler() {
processorMap.put(hIncrbyRequestProcessor.getCmdCode().value(), hIncrbyRequestProcessor);
HIncrbyfloatRequestProcessor hIncrbyfloatRequestProcessor = new HIncrbyfloatRequestProcessor();
processorMap.put(hIncrbyfloatRequestProcessor.getCmdCode().value(), hIncrbyfloatRequestProcessor);
HLenRequestProcessor hLenRequestProcessor = new HLenRequestProcessor();
processorMap.put(hLenRequestProcessor.getCmdCode().value(), hLenRequestProcessor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,7 +30,7 @@
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.HDelRequest;
import icu.funkye.redispike.protocol.request.hash.HDelRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HDelRequestProcessor extends AbstractRedisRequestProcessor<HDelRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;

import java.util.Optional;
package icu.funkye.redispike.handler.process.impl.hash;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
Expand All @@ -27,7 +25,7 @@
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.HExistsRequest;
import icu.funkye.redispike.protocol.request.hash.HExistsRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HExistsRequestProcessor extends AbstractRedisRequestProcessor<HExistsRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.listener.RecordListener;
import com.alipay.remoting.RemotingContext;
import com.alipay.sofa.common.profile.StringUtil;

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.HGetAllRequest;
import icu.funkye.redispike.protocol.request.HGetRequest;
import icu.funkye.redispike.protocol.request.hash.HGetAllRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HGetAllRequestProcessor extends AbstractRedisRequestProcessor<HGetAllRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.listener.RecordListener;
import com.alipay.remoting.RemotingContext;
import com.alipay.sofa.common.profile.StringUtil;

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.HGetRequest;
import icu.funkye.redispike.protocol.request.hash.HGetRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HGetRequestProcessor extends AbstractRedisRequestProcessor<HGetRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@
* 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;
package icu.funkye.redispike.handler.process.impl.hash;

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.protocol.request.hash.HIncrbyRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HIncrbyRequestProcessor extends AbstractRedisRequestProcessor<HIncrbyRequest> {
Expand All @@ -44,7 +37,6 @@ public class HIncrbyRequestProcessor extends AbstractRedisRequestProcessor<HIncr
public HIncrbyRequestProcessor() {
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HIncrbyRequest.class.hashCode()));
this.defaultWritePolicy = client.getWritePolicyDefault();
this.defaultWritePolicy.sendKey = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
Expand All @@ -28,8 +28,7 @@
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.protocol.request.hash.HIncrbyfloatRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HIncrbyfloatRequestProcessor extends AbstractRedisRequestProcessor<HIncrbyfloatRequest> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.hash;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Language;
import com.aerospike.client.Record;
import com.aerospike.client.listener.DeleteListener;
import com.aerospike.client.listener.ExecuteListener;
import com.aerospike.client.listener.RecordListener;
import com.aerospike.client.listener.WriteListener;
import com.aerospike.client.task.RegisterTask;
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.hash.HDelRequest;
import icu.funkye.redispike.protocol.request.hash.HLenRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HLenRequestProcessor extends AbstractRedisRequestProcessor<HLenRequest> {

public HLenRequestProcessor() {
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HLenRequest.class.hashCode()));
RegisterTask task = client.register(null, this.getClass().getClassLoader(), "lua/hlen.lua", "hlen.lua",
Language.LUA);
task.waitTillComplete();
}

@Override
public void handle(RemotingContext ctx, HLenRequest request) {
Key key = new Key(AeroSpikeClientFactory.namespace, AeroSpikeClientFactory.set, request.getKey());
client.execute(AeroSpikeClientFactory.eventLoops.next(), new ExecuteListener() {
@Override
public void onSuccess(Key key, Object obj) {
request.setResponse(obj.toString());
write(ctx, request);
}

@Override
public void onFailure(AerospikeException exception) {
logger.error(exception.getMessage(), exception);
write(ctx, request);
}
}, client.getWritePolicyDefault(), key, "hlen", "hash_count_bins");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import java.util.Optional;
import com.aerospike.client.AerospikeException;
Expand All @@ -26,7 +26,7 @@
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.HMgetRequest;
import icu.funkye.redispike.protocol.request.hash.HMgetRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HMgetRequestProcessor extends AbstractRedisRequestProcessor<HMgetRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -29,7 +29,7 @@
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.HSetRequest;
import icu.funkye.redispike.protocol.request.hash.HSetRequest;
import icu.funkye.redispike.protocol.request.conts.Operate;
import icu.funkye.redispike.util.IntegerUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.hash;

import java.util.Optional;
import com.aerospike.client.AerospikeException;
Expand All @@ -26,7 +26,7 @@
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.HValsRequest;
import icu.funkye.redispike.protocol.request.hash.HValsRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HValsRequestProcessor extends AbstractRedisRequestProcessor<HValsRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.set;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -29,7 +29,7 @@
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.SAddRequest;
import icu.funkye.redispike.protocol.request.set.SAddRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class SAddRequestProcessor extends AbstractRedisRequestProcessor<SAddRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.set;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
import com.aerospike.client.Language;
import com.aerospike.client.Value;
import com.aerospike.client.listener.ExecuteListener;
import com.aerospike.client.task.RegisterTask;
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.SCardRequest;
import icu.funkye.redispike.protocol.request.SRemRequest;
import icu.funkye.redispike.protocol.request.set.SCardRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class SCardRequestProcessor extends AbstractRedisRequestProcessor<SCardRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package icu.funkye.redispike.handler.process.impl;
package icu.funkye.redispike.handler.process.impl.set;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
Expand All @@ -25,7 +25,7 @@
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.SMembersRequest;
import icu.funkye.redispike.protocol.request.set.SMembersRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class SMembersRequestProcessor extends AbstractRedisRequestProcessor<SMembersRequest> {
Expand Down
Loading

0 comments on commit 192c9cf

Please sign in to comment.