Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support hvals protocol #25

Merged
merged 62 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
bd41bdf
optimize: update README.md
funky-eyes Apr 8, 2024
bc98ee3
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into 0408
funky-eyes Apr 8, 2024
589a6b2
optimize: update README.md
funky-eyes Apr 8, 2024
5369351
feature: support keys protocol
funky-eyes Apr 8, 2024
f7d6506
feature: support keys protocol
funky-eyes Apr 8, 2024
96d3450
feature: support keys protocol
funky-eyes Apr 8, 2024
03ffe17
feature: support keys protocol
funky-eyes Apr 8, 2024
3624af8
feature: support keys protocol
funky-eyes Apr 8, 2024
480a6a5
feature: support keys protocol
funky-eyes Apr 8, 2024
aafa4d2
test
funky-eyes Apr 8, 2024
69c9d63
test
funky-eyes Apr 8, 2024
51dbda6
test
funky-eyes Apr 8, 2024
1b03431
test
funky-eyes Apr 8, 2024
6d111db
test
funky-eyes Apr 8, 2024
a4babb5
test
funky-eyes Apr 8, 2024
7886891
test
funky-eyes Apr 8, 2024
ea0c0e0
test
funky-eyes Apr 8, 2024
12ab842
test
funky-eyes Apr 8, 2024
6622391
test
funky-eyes Apr 8, 2024
23c0c6f
test
funky-eyes Apr 8, 2024
d9530e7
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into 0409
funky-eyes Apr 9, 2024
7c521c1
feature: support hgetall&hget protocol
funky-eyes Apr 9, 2024
36ef267
feature: support hgetall&hget protocol
funky-eyes Apr 9, 2024
a1a8784
feature: support hgetall&hget protocol
funky-eyes Apr 9, 2024
4882e36
feature: support hgetall&hget protocol
funky-eyes Apr 9, 2024
ca3fe6c
feature: support hgetall&hget protocol
funky-eyes Apr 9, 2024
786c453
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into 0409
funky-eyes Apr 9, 2024
fd1b040
feature: support sadd&smemebers&spop protocol
funky-eyes Apr 9, 2024
f9efb70
feature: support sadd&smemebers&spop protocol
funky-eyes Apr 9, 2024
eb002e4
test: add pippline test case
funky-eyes Apr 9, 2024
02e700a
test: add pippline test case
funky-eyes Apr 9, 2024
4f70b62
test: add pippline test case
funky-eyes Apr 9, 2024
dde9cdd
test: add pippline test case
funky-eyes Apr 9, 2024
3220013
test: add pippline test case
funky-eyes Apr 9, 2024
931af9e
optimize: add graalvm metadata
funky-eyes Apr 10, 2024
420d620
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into pip…
funky-eyes Apr 10, 2024
0fc82df
optimize: add graalvm metadata
funky-eyes Apr 10, 2024
d91f3e9
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into pip…
funky-eyes Apr 10, 2024
5dd5272
feature: support srandmember protocol
funky-eyes Apr 10, 2024
bdc6e4f
feature: support srem protocol
funky-eyes Apr 10, 2024
56c8177
feature: support srem protocol
funky-eyes Apr 10, 2024
2992829
feature: support srem protocol
funky-eyes Apr 10, 2024
3dd6d03
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into pip…
funky-eyes Apr 10, 2024
d41582e
feature: support scard protocol
funky-eyes Apr 11, 2024
7cbcf68
feature: support pipeline protocol
funky-eyes Apr 11, 2024
fb04c9e
feature: support pipeline protocol
funky-eyes Apr 11, 2024
8335f90
update
funky-eyes Apr 11, 2024
2fc359b
feature: support pipeline protocol
funky-eyes Apr 11, 2024
e6235ec
feature: support pipeline protocol
funky-eyes Apr 11, 2024
ff2072a
feature: support pipeline protocol
funky-eyes Apr 11, 2024
751f868
feature: support pipeline protocol
funky-eyes Apr 11, 2024
5d98564
feature: support hmget protocol
funky-eyes Apr 11, 2024
f26ebdc
Merge branch 'main' of github.com:funky-eyes/redispike-proxy into 0411
funky-eyes Apr 11, 2024
c9b5229
feature: support hmget protocol
funky-eyes Apr 11, 2024
32c7834
feature: support hmget protocol
funky-eyes Apr 11, 2024
4f859d8
feature: support hmget protocol
funky-eyes Apr 11, 2024
cab3381
feature: support hexists protocol
funky-eyes Apr 12, 2024
b976e69
update
funky-eyes Apr 12, 2024
edb67d7
feature: support hexists protocol
funky-eyes Apr 12, 2024
12a5262
feature: support hvals protocol
funky-eyes Apr 12, 2024
f682afa
update
funky-eyes Apr 12, 2024
b4c5f1d
feature: support hvals protocol
funky-eyes Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import icu.funkye.redispike.handler.process.impl.HGetRequestProcessor;
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.KeysRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SCardRequestProcessor;
import icu.funkye.redispike.handler.process.impl.SPopRequestProcessor;
Expand All @@ -52,9 +53,9 @@

public class RedisCommandHandler implements CommandHandler {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());

Map<Short, RemotingProcessor<RedisRequest>> processorMap = new HashMap<>();
Map<Short, RemotingProcessor<RedisRequest<?>>> processorMap = new HashMap<>();

public RedisCommandHandler() {
CommandRequestProcessor commandRequestProcessor = new CommandRequestProcessor();
Expand Down Expand Up @@ -91,6 +92,8 @@ public RedisCommandHandler() {
processorMap.put(sCardRequestProcessor.getCmdCode().value(), sCardRequestProcessor);
HExistsRequestProcessor hExistsRequestProcessor = new HExistsRequestProcessor();
processorMap.put(hExistsRequestProcessor.getCmdCode().value(), hExistsRequestProcessor);
HValsRequestProcessor hValsRequestProcessor = new HValsRequestProcessor();
processorMap.put(hValsRequestProcessor.getCmdCode().value(), hValsRequestProcessor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.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.HValsRequest;
import icu.funkye.redispike.util.IntegerUtils;

public class HValsRequestProcessor extends AbstractRedisRequestProcessor<HValsRequest> {

public HValsRequestProcessor() {
this.cmdCode = new RedisRequestCommandCode(IntegerUtils.hashCodeToShort(HValsRequest.class.hashCode()));
}

@Override
public void handle(RemotingContext ctx, HValsRequest 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.values().forEach(v ->
request.setResponse(v.toString())
));
write(ctx, request);
}

@Override
public void onFailure(AerospikeException ae) {
logger.error(ae.getMessage(), ae);
write(ctx,request);
}
}, client.getReadPolicyDefault(), key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import icu.funkye.redispike.protocol.request.HGetRequest;
import icu.funkye.redispike.protocol.request.HMgetRequest;
import icu.funkye.redispike.protocol.request.HSetRequest;
import icu.funkye.redispike.protocol.request.HValsRequest;
import icu.funkye.redispike.protocol.request.KeysRequest;
import icu.funkye.redispike.protocol.request.SAddRequest;
import icu.funkye.redispike.protocol.request.SCardRequest;
Expand Down Expand Up @@ -116,6 +117,8 @@ private AbstractRedisRequest<?> convert2RedisRequest(List<String> params, boolea
return new HGetRequest(params.get(1), params.size() > 2 ? params.get(2) : null, flush);
case "hgetall":
return new HGetAllRequest(params.get(1), flush);
case "hvals":
return new HValsRequest(params.get(1), flush);
case "hexists":
return new HExistsRequest(params.get(1), params.get(2), flush);
case "scard":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public HExistsRequest(String key, String field, boolean flush) {
this.key = key;
if (StringUtils.isBlank(field)) {
BulkResponse response = new BulkResponse();
response.setError("ERR wrong number of arguments for 'hget' command");
response.setError("ERR wrong number of arguments for 'hexists' command");
this.response = response;
} else {
this.response = new IntegerResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 com.alipay.remoting.util.StringUtils;

import icu.funkye.redispike.protocol.AbstractRedisRequest;
import icu.funkye.redispike.protocol.RedisResponse;
import icu.funkye.redispike.protocol.response.BulkResponse;

public class HValsRequest extends AbstractRedisRequest<String> {

final String key;

BulkResponse response = new BulkResponse(new ArrayList<>());

public HValsRequest(String key, boolean flush) {
this.flush = flush;
this.key = key;
if (StringUtils.isBlank(key)) {
response.setError("ERR wrong number of arguments for 'hvals' command");
}
}

public String getKey() {
return key;
}

@Override
public void setResponse(String data) {
this.response.appender(data);
}

@Override
public RedisResponse<String> getResponse() {
return response;
}

public void setResponse(BulkResponse response) {
this.response = response;
}

public void setError(String errorMsg) {
this.response.setError(errorMsg);
}

}
4 changes: 4 additions & 0 deletions src/test/java/icu/funkye/redispike/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public void testhHash() {
Assertions.assertEquals(result, 2);
List<String> list = jedis.hmget(key, "b", "d");
Assertions.assertEquals(list.size(), 2);
list = jedis.hvals(key);
Assertions.assertEquals(list.size(), 2);
result = jedis.hdel(key, map.keySet().toArray(new String[0]));
Assertions.assertEquals(result, 2);
key = String.valueOf(ThreadLocalRandom.current().nextInt(RandomValue));
Expand All @@ -183,6 +185,8 @@ public void testhHash() {
Assertions.assertEquals(map.size(), 1);
result = jedis.del(key);
Assertions.assertEquals(result, 1);
list = jedis.hvals(key);
Assertions.assertEquals(list.size(), 0);
}
}

Expand Down