-
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 hgetall&hget protocol
- Loading branch information
1 parent
d9530e7
commit 7c521c1
Showing
13 changed files
with
316 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,13 @@ jobs: | |
- name: "Print maven version" | ||
run: ./mvnw -version | ||
- name: "Test, Check style, Check PMD, Check license with Maven and Java" | ||
if: matrix.java == '8' | ||
run: | | ||
./mvnw -T 4C clean test -Dasp-client.version=6.3.0 && sh ./tools/check_format.sh | ||
- name: "Test with Maven and Java${{ matrix.java }}" | ||
if: matrix.java != '8' | ||
run: | | ||
./mvnw -T 4C clean test && sh ./tools/check_format.sh | ||
./mvnw -T 4C clean test | ||
- name: "Codecov" | ||
if: matrix.java == '8' | ||
uses: codecov/[email protected] | ||
|
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
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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/icu/funkye/redispike/handler/process/impl/HGetAllRequestProcessor.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,63 @@ | ||
/* | ||
* 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.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.util.IntegerUtils; | ||
|
||
public class HGetAllRequestProcessor extends AbstractRedisRequestProcessor<HGetAllRequest> { | ||
|
||
public HGetAllRequestProcessor() { | ||
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HGetAllRequest.class.hashCode())); | ||
} | ||
|
||
@Override | ||
public void handle(RemotingContext ctx, HGetAllRequest 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) { | ||
ctx.writeAndFlush(request.getResponse()); | ||
return; | ||
} | ||
record.bins.forEach((k,v)-> { | ||
request.setResponse(k); | ||
request.setResponse(v.toString()); | ||
}); | ||
ctx.writeAndFlush(request.getResponse()); | ||
} | ||
|
||
@Override | ||
public void onFailure(AerospikeException ae) { | ||
logger.error(ae.getMessage(), ae); | ||
ctx.writeAndFlush(request.getResponse()); | ||
} | ||
}, client.getReadPolicyDefault(), key); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/icu/funkye/redispike/handler/process/impl/HGetRequestProcessor.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,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.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.util.IntegerUtils; | ||
|
||
public class HGetRequestProcessor extends AbstractRedisRequestProcessor<HGetRequest> { | ||
|
||
public HGetRequestProcessor() { | ||
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HGetRequest.class.hashCode())); | ||
} | ||
|
||
@Override | ||
public void handle(RemotingContext ctx, HGetRequest request) { | ||
if (request.getField() == null) { | ||
ctx.writeAndFlush(request.getResponse()); | ||
return; | ||
} | ||
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) { | ||
ctx.writeAndFlush(request.getResponse()); | ||
return; | ||
} | ||
String value = record.getString(request.getField()); | ||
if (StringUtil.isNotBlank(value)) { | ||
request.setResponse(value); | ||
} | ||
ctx.writeAndFlush(request.getResponse()); | ||
} | ||
|
||
@Override | ||
public void onFailure(AerospikeException ae) { | ||
logger.error(ae.getMessage(), ae); | ||
ctx.writeAndFlush(request.getResponse()); | ||
} | ||
}, client.getReadPolicyDefault(), key, request.getField()); | ||
} | ||
} |
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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/icu/funkye/redispike/protocol/request/HGetAllRequest.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,52 @@ | ||
/* | ||
* 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.ArrayList; | ||
import icu.funkye.redispike.protocol.RedisRequest; | ||
import icu.funkye.redispike.protocol.RedisResponse; | ||
import icu.funkye.redispike.protocol.response.BulkResponse; | ||
|
||
public class HGetAllRequest implements RedisRequest<String> { | ||
|
||
String key; | ||
|
||
BulkResponse response = new BulkResponse(new ArrayList<>()); | ||
|
||
public HGetAllRequest(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public void setResponse(String data) { | ||
this.response.appender(data); | ||
} | ||
|
||
@Override | ||
public RedisResponse<String> getResponse() { | ||
return response; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GetRequest{" + "key='" + key + '\'' + ", response=" + response + '}'; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/icu/funkye/redispike/protocol/request/HGetRequest.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,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 com.alipay.remoting.util.StringUtils; | ||
import icu.funkye.redispike.protocol.RedisRequest; | ||
import icu.funkye.redispike.protocol.RedisResponse; | ||
import icu.funkye.redispike.protocol.response.BulkResponse; | ||
|
||
public class HGetRequest implements RedisRequest<String> { | ||
|
||
final String key; | ||
|
||
final String field; | ||
|
||
BulkResponse response = new BulkResponse(); | ||
|
||
public HGetRequest(String key, String field) { | ||
this.key = key; | ||
if (StringUtils.isBlank(field)) { | ||
response.setError("ERR wrong number of arguments for 'hget' command"); | ||
} | ||
this.field = field; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public void setResponse(String data) { | ||
this.response.setData(data); | ||
} | ||
|
||
@Override | ||
public RedisResponse<String> getResponse() { | ||
return response; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setResponse(BulkResponse response) { | ||
this.response = response; | ||
} | ||
|
||
public void setError(String errorMsg) { | ||
this.response.setError(errorMsg); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HGetRequest{" + "key='" + key + '\'' + ", field='" + field + '\'' + ", response=" + response + '}'; | ||
} | ||
} |
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
Oops, something went wrong.