Skip to content

Commit

Permalink
Merge branch 'aws:main' into sort_ro_python
Browse files Browse the repository at this point in the history
  • Loading branch information
GilboaAWS authored Jun 6, 2024
2 parents 21c1427 + f058fb7 commit afcaf4e
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 219 deletions.
69 changes: 0 additions & 69 deletions .github/workflows/install-redis-modules/action.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ jobs:
target: "x86_64-unknown-linux-gnu"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Redis Modules
uses: ./.github/workflows/install-redis-modules
with:
redis-version: ${{ matrix.redis }}

- name: test
run: npm test
working-directory: ./node
Expand All @@ -83,10 +78,6 @@ jobs:
npm ci
npm run build-and-test
working-directory: ./node/hybrid-node-tests/ecmascript-test

- name: test redis modules
run: npm run test-modules -- --load-module=$GITHUB_WORKSPACE/redisjson.so
working-directory: ./node

- uses: ./.github/workflows/test-benchmark
with:
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,12 @@ jobs:
pip install -r ../benchmarks/python/requirements.txt
python -m mypy ..
- name: Install Redis Modules
uses: ./.github/workflows/install-redis-modules
with:
redis-version: ${{ matrix.redis }}

- name: Test with pytest
working-directory: ./python
run: |
source .env/bin/activate
cd python/tests/
pytest --asyncio-mode=auto --override-ini=addopts= --load-module=$GITHUB_WORKSPACE/redisjson.so
pytest --asyncio-mode=auto
- uses: ./.github/workflows/test-benchmark
with:
Expand Down
80 changes: 62 additions & 18 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.SMIsMember;
import static redis_request.RedisRequestOuterClass.RequestType.SMembers;
import static redis_request.RedisRequestOuterClass.RequestType.SMove;
import static redis_request.RedisRequestOuterClass.RequestType.SPop;
import static redis_request.RedisRequestOuterClass.RequestType.SRandMember;
import static redis_request.RedisRequestOuterClass.RequestType.SRem;
import static redis_request.RedisRequestOuterClass.RequestType.SUnionStore;
Expand Down Expand Up @@ -186,6 +187,8 @@
import glide.managers.BaseCommandResponseResolver;
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -244,7 +247,8 @@ protected static <T> CompletableFuture<T> CreateClient(
.connectToRedis(config)
.thenApply(ignore -> constructor.apply(connectionManager, commandManager));
} catch (InterruptedException e) {
// Something bad happened while we were establishing netty connection to UDS
// Something bad happened while we were establishing netty connection to
// UDS
var future = new CompletableFuture<T>();
future.completeExceptionally(e);
return future;
Expand All @@ -263,7 +267,8 @@ public void close() throws ExecutionException {
try {
connectionManager.closeConnection().get();
} catch (InterruptedException e) {
// suppressing the interrupted exception - it is already suppressed in the future
// suppressing the interrupted exception - it is already suppressed in the
// future
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -295,10 +300,15 @@ protected static CommandManager buildCommandManager(ChannelHandler channelHandle
* @throws RedisException On a type mismatch.
*/
@SuppressWarnings("unchecked")
protected <T> T handleRedisResponse(Class<T> classType, boolean isNullable, Response response)
throws RedisException {
protected <T> T handleRedisResponse(
Class<T> classType, EnumSet<ResponseFlags> flags, Response response) throws RedisException {
boolean encodingUtf8 = flags.contains(ResponseFlags.ENCODING_UTF8);
boolean isNullable = flags.contains(ResponseFlags.IS_NULLABLE);
Object value =
new BaseCommandResponseResolver(RedisValueResolver::valueFromPointer).apply(response);
encodingUtf8
? new BaseCommandResponseResolver(RedisValueResolver::valueFromPointer).apply(response)
: new BaseCommandResponseResolver(RedisValueResolver::valueFromPointerBinary)
.apply(response);
if (isNullable && (value == null)) {
return null;
}
Expand All @@ -314,43 +324,52 @@ protected <T> T handleRedisResponse(Class<T> classType, boolean isNullable, Resp
}

protected Object handleObjectOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(Object.class, true, response);
return handleRedisResponse(
Object.class, EnumSet.of(ResponseFlags.IS_NULLABLE, ResponseFlags.ENCODING_UTF8), response);
}

protected String handleStringResponse(Response response) throws RedisException {
return handleRedisResponse(String.class, false, response);
return handleRedisResponse(String.class, EnumSet.of(ResponseFlags.ENCODING_UTF8), response);
}

protected String handleStringOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(String.class, true, response);
return handleRedisResponse(
String.class, EnumSet.of(ResponseFlags.IS_NULLABLE, ResponseFlags.ENCODING_UTF8), response);
}

protected byte[] handleBytesOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(byte[].class, EnumSet.of(ResponseFlags.IS_NULLABLE), response);
}

protected Boolean handleBooleanResponse(Response response) throws RedisException {
return handleRedisResponse(Boolean.class, false, response);
return handleRedisResponse(Boolean.class, EnumSet.noneOf(ResponseFlags.class), response);
}

protected Long handleLongResponse(Response response) throws RedisException {
return handleRedisResponse(Long.class, false, response);
return handleRedisResponse(Long.class, EnumSet.noneOf(ResponseFlags.class), response);
}

protected Long handleLongOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(Long.class, true, response);
return handleRedisResponse(Long.class, EnumSet.of(ResponseFlags.IS_NULLABLE), response);
}

protected Double handleDoubleResponse(Response response) throws RedisException {
return handleRedisResponse(Double.class, false, response);
return handleRedisResponse(Double.class, EnumSet.noneOf(ResponseFlags.class), response);
}

protected Double handleDoubleOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(Double.class, true, response);
return handleRedisResponse(Double.class, EnumSet.of(ResponseFlags.IS_NULLABLE), response);
}

protected Object[] handleArrayResponse(Response response) throws RedisException {
return handleRedisResponse(Object[].class, false, response);
return handleRedisResponse(Object[].class, EnumSet.of(ResponseFlags.ENCODING_UTF8), response);
}

protected Object[] handleArrayOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(Object[].class, true, response);
return handleRedisResponse(
Object[].class,
EnumSet.of(ResponseFlags.IS_NULLABLE, ResponseFlags.ENCODING_UTF8),
response);
}

/**
Expand All @@ -360,7 +379,7 @@ protected Object[] handleArrayOrNullResponse(Response response) throws RedisExce
*/
@SuppressWarnings("unchecked") // raw Map cast to Map<String, V>
protected <V> Map<String, V> handleMapResponse(Response response) throws RedisException {
return handleRedisResponse(Map.class, false, response);
return handleRedisResponse(Map.class, EnumSet.of(ResponseFlags.ENCODING_UTF8), response);
}

/**
Expand All @@ -370,12 +389,13 @@ protected <V> Map<String, V> handleMapResponse(Response response) throws RedisEx
*/
@SuppressWarnings("unchecked") // raw Map cast to Map<String, V>
protected <V> Map<String, V> handleMapOrNullResponse(Response response) throws RedisException {
return handleRedisResponse(Map.class, true, response);
return handleRedisResponse(
Map.class, EnumSet.of(ResponseFlags.IS_NULLABLE, ResponseFlags.ENCODING_UTF8), response);
}

@SuppressWarnings("unchecked") // raw Set cast to Set<String>
protected Set<String> handleSetResponse(Response response) throws RedisException {
return handleRedisResponse(Set.class, false, response);
return handleRedisResponse(Set.class, EnumSet.of(ResponseFlags.ENCODING_UTF8), response);
}

/** Process a <code>FUNCTION LIST</code> standalone response. */
Expand All @@ -401,12 +421,24 @@ public CompletableFuture<String> get(@NonNull String key) {
Get, new String[] {key}, this::handleStringOrNullResponse);
}

@Override
public CompletableFuture<byte[]> get(@NonNull byte[] key) {
return commandManager.submitNewCommand(
Get, Arrays.asList(key), this::handleBytesOrNullResponse);
}

@Override
public CompletableFuture<String> getdel(@NonNull String key) {
return commandManager.submitNewCommand(
GetDel, new String[] {key}, this::handleStringOrNullResponse);
}

@Override
public CompletableFuture<String> set(@NonNull byte[] key, @NonNull byte[] value) {
return commandManager.submitNewCommand(
Set, Arrays.asList(key, value), this::handleStringResponse);
}

@Override
public CompletableFuture<String> set(@NonNull String key, @NonNull String value) {
return commandManager.submitNewCommand(
Expand Down Expand Up @@ -1656,6 +1688,18 @@ public CompletableFuture<String[]> srandmember(@NonNull String key, long count)
SRandMember, arguments, response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<String> spop(@NonNull String key) {
String[] arguments = new String[] {key};
return commandManager.submitNewCommand(SPop, arguments, this::handleStringOrNullResponse);
}

@Override
public CompletableFuture<Set<String>> spopCount(@NonNull String key, long count) {
String[] arguments = new String[] {key, Long.toString(count)};
return commandManager.submitNewCommand(SPop, arguments, this::handleSetResponse);
}

@Override
public CompletableFuture<Long[]> bitfield(
@NonNull String key, @NonNull BitFieldSubCommands[] subCommands) {
Expand Down
9 changes: 9 additions & 0 deletions java/client/src/main/java/glide/api/ResponseFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api;

public enum ResponseFlags {
/** Strings in the response are UTF-8 encoded */
ENCODING_UTF8,
/** Null is a valid response */
IS_NULLABLE,
}
38 changes: 38 additions & 0 deletions java/client/src/main/java/glide/api/commands/SetBaseCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,42 @@ public interface SetBaseCommands {
* }</pre>
*/
CompletableFuture<String[]> srandmember(String key, long count);

/**
* Removes and returns one random member from the set stored at <code>key</code>.
*
* @see <a href="https://redis.io/commands/spop/">redis.io</a> for details.
* @param key The key of the set.
* @return The value of the popped member.<br>
* If <code>key</code> does not exist, <code>null</code> will be returned.
* @example
* <pre>{@code
* String value1 = client.spop("mySet").get();
* assert value1.equals("value1");
*
* String value2 = client.spop("nonExistingSet").get();
* assert value2.equals(null);
* }</pre>
*/
CompletableFuture<String> spop(String key);

/**
* Removes and returns up to <code>count</code> random members from the set stored at <code>key
* </code>, depending on the set's length.
*
* @see <a href="https://redis.io/commands/spop/">redis.io</a> for details.
* @param key The key of the set.
* @param count The count of the elements to pop from the set.
* @return A set of popped elements will be returned depending on the set's length.<br>
* If <code>key</code> does not exist, an empty <code>Set</code> will be returned.
* @example
* <pre>{@code
* Set<String> values1 = client.spopCount("mySet", 2).get();
* assert values1.equals(new String[] {"value1", "value2"});
*
* Set<String> values2 = client.spopCount("nonExistingSet", 2).get();
* assert values2.size() == 0;
* }</pre>
*/
CompletableFuture<Set<String>> spopCount(String key, long count);
}
Loading

0 comments on commit afcaf4e

Please sign in to comment.