Skip to content

Commit

Permalink
Merge branch 'main' into python/integ_yipin_setrange
Browse files Browse the repository at this point in the history
  • Loading branch information
acarbonetto authored May 24, 2024
2 parents c8960d0 + 7e1e04d commit a363fdd
Show file tree
Hide file tree
Showing 20 changed files with 776 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
* Python: Added SINTER command ([#1434](https://github.com/aws/glide-for-redis/pull/1434))
* Python: Added SDIFF command ([#1437](https://github.com/aws/glide-for-redis/pull/1437))
* Python: Added SDIFFSTORE command ([#1449](https://github.com/aws/glide-for-redis/pull/1449))
* Python: Added SINTERSTORE command ([#1459](https://github.com/aws/glide-for-redis/pull/1459))
* Python: Added SMISMEMBER command ([#1461](https://github.com/aws/glide-for-redis/pull/1461))
* Python: Added SETRANGE command ([#1453](https://github.com/aws/glide-for-redis/pull/1453)


#### Fixes
* Python: Fix typing error "‘type’ object is not subscriptable" ([#1203](https://github.com/aws/glide-for-redis/pull/1203))
* Core: Fixed blocking commands to use the specified timeout from the command argument ([#1283](https://github.com/aws/glide-for-redis/pull/1283))
Expand Down
2 changes: 1 addition & 1 deletion glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
b"HGETALL" | b"XREAD" | b"CONFIG GET" | b"FT.CONFIG GET" | b"HELLO" => {
Some(ExpectedReturnType::Map)
}
b"INCRBYFLOAT" | b"HINCRBYFLOAT" => Some(ExpectedReturnType::Double),
b"INCRBYFLOAT" | b"HINCRBYFLOAT" | b"ZINCRBY" => Some(ExpectedReturnType::Double),
b"HEXISTS" | b"HSETNX" | b"EXPIRE" | b"EXPIREAT" | b"PEXPIRE" | b"PEXPIREAT"
| b"SISMEMBER" | b"PERSIST" | b"SMOVE" | b"RENAMENX" => Some(ExpectedReturnType::Boolean),
b"SMISMEMBER" => Some(ExpectedReturnType::ArrayOfBools),
Expand Down
1 change: 1 addition & 0 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ enum RequestType {
GetBit = 145;
ZInter = 146;
BitPos = 147;
BitOp = 148;
FunctionLoad = 150;
}

Expand Down
3 changes: 3 additions & 0 deletions glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub enum RequestType {
GetBit = 145,
ZInter = 146,
BitPos = 147,
BitOp = 148,
FunctionLoad = 150,
}

Expand Down Expand Up @@ -319,6 +320,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::ZInter => RequestType::ZInter,
ProtobufRequestType::FunctionLoad => RequestType::FunctionLoad,
ProtobufRequestType::BitPos => RequestType::BitPos,
ProtobufRequestType::BitOp => RequestType::BitOp,
}
}
}
Expand Down Expand Up @@ -476,6 +478,7 @@ impl RequestType {
RequestType::ZInter => Some(cmd("ZINTER")),
RequestType::FunctionLoad => Some(get_two_word_command("FUNCTION", "LOAD")),
RequestType::BitPos => Some(cmd("BITPOS")),
RequestType::BitOp => Some(cmd("BITOP")),
}
}
}
44 changes: 44 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.BZPopMax;
import static redis_request.RedisRequestOuterClass.RequestType.BZPopMin;
import static redis_request.RedisRequestOuterClass.RequestType.BitCount;
import static redis_request.RedisRequestOuterClass.RequestType.BitOp;
import static redis_request.RedisRequestOuterClass.RequestType.BitPos;
import static redis_request.RedisRequestOuterClass.RequestType.Decr;
import static redis_request.RedisRequestOuterClass.RequestType.DecrBy;
Expand All @@ -38,6 +39,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.HKeys;
import static redis_request.RedisRequestOuterClass.RequestType.HLen;
import static redis_request.RedisRequestOuterClass.RequestType.HMGet;
import static redis_request.RedisRequestOuterClass.RequestType.HRandField;
import static redis_request.RedisRequestOuterClass.RequestType.HSet;
import static redis_request.RedisRequestOuterClass.RequestType.HSetNX;
import static redis_request.RedisRequestOuterClass.RequestType.HVals;
Expand Down Expand Up @@ -97,6 +99,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.ZCount;
import static redis_request.RedisRequestOuterClass.RequestType.ZDiff;
import static redis_request.RedisRequestOuterClass.RequestType.ZDiffStore;
import static redis_request.RedisRequestOuterClass.RequestType.ZIncrBy;
import static redis_request.RedisRequestOuterClass.RequestType.ZInter;
import static redis_request.RedisRequestOuterClass.RequestType.ZInterCard;
import static redis_request.RedisRequestOuterClass.RequestType.ZInterStore;
Expand Down Expand Up @@ -143,6 +146,7 @@
import glide.api.models.commands.WeightAggregateOptions.KeysOrWeightedKeys;
import glide.api.models.commands.ZAddOptions;
import glide.api.models.commands.bitmap.BitmapIndexType;
import glide.api.models.commands.bitmap.BitwiseOperation;
import glide.api.models.commands.geospatial.GeoAddOptions;
import glide.api.models.commands.geospatial.GeoUnit;
import glide.api.models.commands.geospatial.GeospatialData;
Expand Down Expand Up @@ -538,6 +542,29 @@ public CompletableFuture<String[]> hkeys(@NonNull String key) {
response -> castArray(handleArrayResponse(response), String.class));
}

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

@Override
public CompletableFuture<String[]> hrandfieldWithCount(@NonNull String key, long count) {
return commandManager.submitNewCommand(
HRandField,
new String[] {key, Long.toString(count)},
response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<String[][]> hrandfieldWithCountWithValues(
@NonNull String key, long count) {
return commandManager.submitNewCommand(
HRandField,
new String[] {key, Long.toString(count), WITH_VALUES_REDIS_API},
response -> castArrayofArrays(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<Long> lpush(@NonNull String key, @NonNull String[] elements) {
String[] arguments = ArrayUtils.addFirst(elements, key);
Expand Down Expand Up @@ -1117,6 +1144,13 @@ public CompletableFuture<Object[][]> zrandmemberWithCountWithScores(
response -> castArray(handleArrayResponse(response), Object[].class));
}

@Override
public CompletableFuture<Double> zincrby(
@NonNull String key, double increment, @NonNull String member) {
String[] arguments = new String[] {key, Double.toString(increment), member};
return commandManager.submitNewCommand(ZIncrBy, arguments, this::handleDoubleResponse);
}

@Override
public CompletableFuture<Long> zintercard(@NonNull String[] keys) {
String[] arguments = ArrayUtils.addFirst(keys, Integer.toString(keys.length));
Expand Down Expand Up @@ -1410,4 +1444,14 @@ public CompletableFuture<Long> bitpos(
};
return commandManager.submitNewCommand(BitPos, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<Long> bitop(
@NonNull BitwiseOperation bitwiseOperation,
@NonNull String destination,
@NonNull String[] keys) {
String[] arguments =
concatenateArrays(new String[] {bitwiseOperation.toString(), destination}, keys);
return commandManager.submitNewCommand(BitOp, arguments, this::handleLongResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package glide.api.commands;

import glide.api.models.commands.bitmap.BitmapIndexType;
import glide.api.models.commands.bitmap.BitwiseOperation;
import java.util.concurrent.CompletableFuture;

/**
Expand Down Expand Up @@ -213,4 +214,27 @@ public interface BitmapBaseCommands {
*/
CompletableFuture<Long> bitpos(
String key, long bit, long start, long end, BitmapIndexType offsetType);

/**
* Perform a bitwise operation between multiple keys (containing string values) and store the
* result in the <code>destination</code>.
*
* @apiNote When in cluster mode, <code>destination</code> and all <code>keys</code> must map to
* the same hash slot.
* @see <a href="https://redis.io/commands/bitop/">redis.io</a> for details.
* @param bitwiseOperation The bitwise operation to perform.
* @param destination The key that will store the resulting string.
* @param keys The list of keys to perform the bitwise operation on.
* @return The size of the string stored in <code>destination</code>.
* @example
* <pre>{@code
* client.set("key1", "A"); // "A" has binary value 01000001
* client.set("key2", "B"); // "B" has binary value 01000010
* Long payload = client.bitop(BitwiseOperation.AND, "destination", new String[] {key1, key2}).get();
* assert "@".equals(client.get("destination").get()); // "@" has binary value 01000000
* assert payload == 1L; // The size of the resulting string is 1.
* }</pre>
*/
CompletableFuture<Long> bitop(
BitwiseOperation bitwiseOperation, String destination, String[] keys);
}
60 changes: 60 additions & 0 deletions java/client/src/main/java/glide/api/commands/HashBaseCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* @see <a href="https://redis.io/commands/?group=hash">Hash Commands</a>
*/
public interface HashBaseCommands {
/** Redis API keyword used to query hash members with their values. */
String WITH_VALUES_REDIS_API = "WITHVALUES";

/**
* Retrieves the value associated with <code>field</code> in the hash stored at <code>key</code>.
Expand Down Expand Up @@ -234,4 +236,62 @@ public interface HashBaseCommands {
* }</pre>
*/
CompletableFuture<String[]> hkeys(String key);

/**
* Returns a random field name from the hash value stored at <code>key</code>.
*
* @since Redis 6.2 and above.
* @see <a href="https://redis.io/commands/hrandfield/">redis.io</a> for details.
* @param key The key of the hash.
* @return A random field name from the hash stored at <code>key</code>, or <code>null</code> when
* the key does not exist.
* @example
* <pre>{@code
* String field = client.hrandfield("my_hash").get();
* System.out.printf("A random field from the hash is '%s'", field);
* }</pre>
*/
CompletableFuture<String> hrandfield(String key);

/**
* Retrieves up to <code>count</code> random field names from the hash value stored at <code>key
* </code>.
*
* @since Redis 6.2 and above.
* @see <a href="https://redis.io/commands/hrandfield/">redis.io</a> for details.
* @param key The key of the hash.
* @param count The number of field names to return.<br>
* If <code>count</code> is positive, returns unique elements.<br>
* If negative, allows for duplicates.
* @return An <code>array</code> of random field names from the hash stored at <code>key</code>,
* or an <code>empty array</code> when the key does not exist.
* @example
* <pre>{@code
* String[] fields = client.hrandfieldWithCount("my_hash", 10).get();
* System.out.printf("Random fields from the hash are '%s'", String.join(", ", fields));
* }</pre>
*/
CompletableFuture<String[]> hrandfieldWithCount(String key, long count);

/**
* Retrieves up to <code>count</code> random field names along with their values from the hash
* value stored at <code>key</code>.
*
* @since Redis 6.2 and above.
* @see <a href="https://redis.io/commands/hrandfield/">redis.io</a> for details.
* @param key The key of the hash.
* @param count The number of field names to return.<br>
* If <code>count</code> is positive, returns unique elements.<br>
* If negative, allows for duplicates.
* @return A 2D <code>array</code> of <code>[fieldName, value]</code> <code>arrays</code>, where
* <code>fieldName</code> is a random field name from the hash and <code>value</code> is the
* associated value of the field name.<br>
* If the hash does not exist or is empty, the response will be an empty <code>array</code>.
* @example
* <pre>{@code
* String[][] fields = client.hrandfieldWithCountWithValues("my_hash", 1).get();
* System.out.printf("A random field from the hash is '%s' and the value is '%s'", fields[0][0], fields[0][1]);
* }</pre>
*/
CompletableFuture<String[][]> hrandfieldWithCountWithValues(String key, long count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ CompletableFuture<Long> zadd(
* If <code>member</code> does not exist in the sorted set, it is added with <code>
* increment</code> as its score (as if its previous score was <code>0.0</code>).<br>
* If <code>key</code> does not exist, a new sorted set with the specified member as its sole
* member is created.
* member is created.<br>
* <code>zaddIncr</code> with empty option acts as {@link #zincrby(String, double, String)}.
*
* @see <a href="https://redis.io/commands/zadd/">redis.io</a> for more details.
* @param key The key of the sorted set.
Expand All @@ -142,11 +143,11 @@ CompletableFuture<Long> zadd(
* returned.
* @example
* <pre>{@code
* ZaddOptions options = ZaddOptions.builder().conditionalChange(ONLY_IF_DOES_NOT_EXIST).build();
* ZAddOptions options = ZaddOptions.builder().conditionalChange(ONLY_IF_DOES_NOT_EXIST).build();
* Double num = client.zaddIncr("mySortedSet", member, 5.0, options).get();
* assert num == 5.0;
*
* options = ZaddOptions.builder().updateOptions(SCORE_LESS_THAN_CURRENT).build();
* options = ZAddOptions.builder().updateOptions(SCORE_LESS_THAN_CURRENT).build();
* Double num = client.zaddIncr("existingSortedSet", member, 3.0, options).get();
* assert num == null;
* }</pre>
Expand Down Expand Up @@ -1377,7 +1378,7 @@ CompletableFuture<Map<String, Double>> zinterWithScores(
* </code>.
* @example
* <pre>{@code
* Object[][] data = client.zrandmemberWithCountWithScores(key1, -3).get();
* Object[][] data = client.zrandmemberWithCountWithScores("mySortedSet", -3).get();
* assert data.length == 3;
* for (Object[] memberScorePair : data) {
* System.out.printf("Member: '%s', score: %d", memberScorePair[0], memberScorePair[1]);
Expand All @@ -1386,6 +1387,26 @@ CompletableFuture<Map<String, Double>> zinterWithScores(
*/
CompletableFuture<Object[][]> zrandmemberWithCountWithScores(String key, long count);

/**
* Increments the score of <code>member</code> in the sorted set stored at <code>key</code> by
* <code>increment</code>.<br>
* If <code>member</code> does not exist in the sorted set, it is added with <code>increment
* </code> as its score. If <code>key</code> does not exist, a new sorted set with the specified
* member as its sole member is created.
*
* @see <a href="https://redis.io/commands/zincrby/">redis.io</a> for more details.
* @param key The key of the sorted set.
* @param increment The score increment.
* @param member A member of the sorted set.
* @return The new score of <code>member</code>.
* @example
* <pre>{@code
* Double score = client.zincrby("mySortedSet", -3.14, "value").get();
* assert score > 0; // member "value" existed in the set before score was altered
* }</pre>
*/
CompletableFuture<Double> zincrby(String key, double increment, String member);

/**
* Returns the cardinality of the intersection of the sorted sets specified by <code>keys</code>.
*
Expand Down
Loading

0 comments on commit a363fdd

Please sign in to comment.