-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support hkeys protocol (#29)
- Loading branch information
1 parent
192c9cf
commit 1c74290
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/icu/funkye/redispike/handler/process/impl/hash/HKeysRequestProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.Optional; | ||
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 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.HKeysRequest; | ||
import icu.funkye.redispike.util.IntegerUtils; | ||
|
||
public class HKeysRequestProcessor extends AbstractRedisRequestProcessor<HKeysRequest> { | ||
|
||
public HKeysRequestProcessor() { | ||
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HKeysRequest.class.hashCode())); | ||
} | ||
|
||
@Override | ||
public void handle(RemotingContext ctx, HKeysRequest request) { | ||
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) { | ||
if (record == null) { | ||
write(ctx, request); | ||
return; | ||
} | ||
Optional.ofNullable(record.bins).ifPresent(bins -> bins.keySet().forEach(request::setResponse)); | ||
write(ctx, request); | ||
} | ||
|
||
@Override | ||
public void onFailure(AerospikeException exception) { | ||
|
||
} | ||
}, client.getReadPolicyDefault(), key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/icu/funkye/redispike/protocol/request/hash/HKeysRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.hash; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import icu.funkye.redispike.protocol.AbstractRedisRequest; | ||
import icu.funkye.redispike.protocol.RedisResponse; | ||
import icu.funkye.redispike.protocol.response.BulkResponse; | ||
|
||
public class HKeysRequest extends AbstractRedisRequest<String> { | ||
|
||
String key; | ||
|
||
BulkResponse response = new BulkResponse(new ArrayList<>()); | ||
|
||
public HKeysRequest(List<String> params, boolean flush) { | ||
this.flush = flush; | ||
this.key = params.remove(0); | ||
} | ||
|
||
@Override | ||
public void setResponse(String data) { | ||
this.response.appender(data); | ||
} | ||
|
||
@Override | ||
public RedisResponse<String> getResponse() { | ||
return response; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters