Skip to content

Commit

Permalink
Merge branch 'main' into node/integ_yipin_pfcount
Browse files Browse the repository at this point in the history
  • Loading branch information
yipin-chen authored Jun 10, 2024
2 parents 19fef90 + 9caf33d commit 5287e9a
Show file tree
Hide file tree
Showing 15 changed files with 635 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Added ZINTERSTORE command ([#1513](https://github.com/aws/glide-for-redis/pull/1513))
* Python: Added OBJECT ENCODING command ([#1471](https://github.com/aws/glide-for-redis/pull/1471))
* Python: Added OBJECT FREQ command ([#1472](https://github.com/aws/glide-for-redis/pull/1472))
* Python: Added OBJECT IDLETIME command ([#1474](https://github.com/aws/glide-for-redis/pull/1474))
Expand All @@ -15,6 +16,7 @@
* Python: Added SINTERCARD command ([#1511](https://github.com/aws/glide-for-redis/pull/1511))
* Python: Added SORT command ([#1439](https://github.com/aws/glide-for-redis/pull/1439))
* Node: Added OBJECT ENCODING command ([#1518](https://github.com/aws/glide-for-redis/pull/1518))
* Python: Added LMOVE and BLMOVE commands ([#1536](https://github.com/aws/glide-for-redis/pull/1536))
* Node: Added PFCOUNT command ([#1545](https://github.com/aws/glide-for-redis/pull/1545))

### Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import glide.api.models.commands.bitmap.BitFieldOptions.OffsetMultiplier;
import glide.api.models.commands.bitmap.BitmapIndexType;
import glide.api.models.commands.bitmap.BitwiseOperation;
import glide.api.models.configuration.ReadFrom;
import java.util.concurrent.CompletableFuture;

/**
Expand All @@ -24,7 +25,7 @@ public interface BitmapBaseCommands {
/**
* Counts the number of set bits (population counting) in a string stored at <code>key</code>.
*
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @return The number of set bits in the string. Returns zero if the key is missing as it is
* treated as an empty string.
Expand All @@ -44,7 +45,7 @@ public interface BitmapBaseCommands {
* <code>-1</code> being the last element of the list, <code>-2</code> being the penultimate, and
* so on.
*
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @param start The starting offset byte index.
* @param end The ending offset byte index.
Expand All @@ -67,7 +68,7 @@ public interface BitmapBaseCommands {
* so on.
*
* @since Redis 7.0 and above
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @param start The starting offset.
* @param end The ending offset.
Expand All @@ -92,7 +93,7 @@ public interface BitmapBaseCommands {
* non-existent then the bit at <code>offset</code> is set to <code>value</code> and the preceding
* bits are set to <code>0</code>.
*
* @see <a href="https://redis.io/commands/setbit/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/setbit/">valkey.io</a> for details.
* @param key The key of the string.
* @param offset The index of the bit to be set.
* @param value The bit value to set at <code>offset</code>. The value must be <code>0</code> or
Expand All @@ -110,7 +111,7 @@ public interface BitmapBaseCommands {
* Returns the bit value at <code>offset</code> in the string value stored at <code>key</code>.
* <code>offset</code> should be greater than or equal to zero.
*
* @see <a href="https://redis.io/commands/getbit/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/getbit/">valkey.io</a> for details.
* @param key The key of the string.
* @param offset The index of the bit to return.
* @return The bit at offset of the string. Returns zero if the key is empty or if the positive
Expand All @@ -127,7 +128,7 @@ public interface BitmapBaseCommands {
/**
* Returns the position of the first bit matching the given <code>bit</code> value.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @return The position of the first occurrence matching <code>bit</code> in the binary value of
Expand All @@ -150,7 +151,7 @@ public interface BitmapBaseCommands {
* indicating offsets starting at the end of the list, with <code>-1</code> being the last byte of
* the list, <code>-2</code> being the penultimate, and so on.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand All @@ -174,7 +175,7 @@ public interface BitmapBaseCommands {
* negative numbers indicating offsets starting at the end of the list, with <code>-1</code> being
* the last byte of the list, <code>-2</code> being the penultimate, and so on.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand Down Expand Up @@ -203,7 +204,7 @@ public interface BitmapBaseCommands {
* list, <code>-2</code> being the penultimate, and so on.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand All @@ -230,7 +231,7 @@ CompletableFuture<Long> bitpos(
*
* @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.
* @see <a href="https://valkey.io/commands/bitop/">valkey.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.
Expand All @@ -251,7 +252,7 @@ CompletableFuture<Long> bitop(
* Reads or modifies the array of bits representing the string that is held at <code>key</code>
* based on the specified <code>subCommands</code>.
*
* @see <a href="https://redis.io/commands/bitfield/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitfield/">valkey.io</a> for details.
* @param key The key of the string.
* @param subCommands The subCommands to be performed on the binary value of the string at <code>
* key</code>, which could be any of the following:
Expand Down Expand Up @@ -289,10 +290,11 @@ CompletableFuture<Long> bitop(

/**
* Reads the array of bits representing the string that is held at <code>key</code> based on the
* specified <code>subCommands</code>.
* specified <code>subCommands</code>.<br>
* This command is routed depending on the client's {@link ReadFrom} strategy.
*
* @since Redis 6.0 and above
* @see <a href="https://redis.io/docs/latest/commands/bitfield_ro/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitfield_ro/">valkey.io</a> for details.
* @param key The key of the string.
* @param subCommands The <code>GET</code> subCommands to be performed.
* @return An array of results from the <code>GET</code> subcommands.
Expand Down
28 changes: 15 additions & 13 deletions java/client/src/main/java/glide/api/models/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
import glide.api.models.commands.stream.StreamAddOptions.StreamAddOptionsBuilder;
import glide.api.models.commands.stream.StreamRange;
import glide.api.models.commands.stream.StreamTrimOptions;
import glide.api.models.configuration.ReadFrom;
import java.util.Arrays;
import java.util.Map;
import lombok.Getter;
Expand Down Expand Up @@ -3500,7 +3501,7 @@ public T copy(@NonNull String source, @NonNull String destination) {
/**
* Counts the number of set bits (population counting) in a string stored at <code>key</code>.
*
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @return Command Response - The number of set bits in the string. Returns zero if the key is
* missing as it is treated as an empty string.
Expand All @@ -3519,7 +3520,7 @@ public T bitcount(@NonNull String key) {
* <code>-1</code> being the last element of the list, <code>-2</code> being the penultimate, and
* so on.
*
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @param start The starting byte offset.
* @param end The ending byte offset.
Expand All @@ -3543,7 +3544,7 @@ public T bitcount(@NonNull String key, long start, long end) {
* so on.
*
* @since Redis 7.0 and above
* @see <a href="https://redis.io/commands/bitcount/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitcount/">valkey.io</a> for details.
* @param key The key for the string to count the set bits of.
* @param start The starting offset.
* @param end The ending offset.
Expand Down Expand Up @@ -3738,7 +3739,7 @@ public T functionList(@NonNull String libNamePattern, boolean withCode) {
* non-existent then the bit at <code>offset</code> is set to <code>value</code> and the preceding
* bits are set to <code>0</code>.
*
* @see <a href="https://redis.io/commands/setbit/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/setbit/">valkey.io</a> for details.
* @param key The key of the string.
* @param offset The index of the bit to be set.
* @param value The bit value to set at <code>offset</code>. The value must be <code>0</code> or
Expand All @@ -3755,7 +3756,7 @@ public T setbit(@NonNull String key, long offset, long value) {
* Returns the bit value at <code>offset</code> in the string value stored at <code>key</code>.
* <code>offset</code> should be greater than or equal to zero.
*
* @see <a href="https://redis.io/commands/getbit/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/getbit/">valkey.io</a> for details.
* @param key The key of the string.
* @param offset The index of the bit to return.
* @return Command Response - The bit at offset of the string. Returns zero if the key is empty or
Expand Down Expand Up @@ -3837,7 +3838,7 @@ public T blmpop(@NonNull String[] keys, @NonNull ListDirection direction, double
/**
* Returns the position of the first bit matching the given <code>bit</code> value.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @return Command Response - The position of the first occurrence matching <code>bit</code> in
Expand All @@ -3857,7 +3858,7 @@ public T bitpos(@NonNull String key, long bit) {
* indicating offsets starting at the end of the list, with <code>-1</code> being the last byte of
* the list, <code>-2</code> being the penultimate, and so on.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand All @@ -3878,7 +3879,7 @@ public T bitpos(@NonNull String key, long bit, long start) {
* negative numbers indicating offsets starting at the end of the list, with <code>-1</code> being
* the last byte of the list, <code>-2</code> being the penultimate, and so on.
*
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand All @@ -3905,7 +3906,7 @@ public T bitpos(@NonNull String key, long bit, long start, long end) {
* list, <code>-2</code> being the penultimate, and so on.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/commands/bitpos/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitpos/">valkey.io</a> for details.
* @param key The key of the string.
* @param bit The bit value to match. The value must be <code>0</code> or <code>1</code>.
* @param start The starting offset.
Expand Down Expand Up @@ -3934,7 +3935,7 @@ public T bitpos(
* Perform a bitwise operation between multiple keys (containing string values) and store the
* result in the <code>destination</code>.
*
* @see <a href="https://redis.io/commands/bitop/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitop/">valkey.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.
Expand Down Expand Up @@ -4147,7 +4148,7 @@ public T spopCount(@NonNull String key, long count) {
* Reads or modifies the array of bits representing the string that is held at <code>key</code>
* based on the specified <code>subCommands</code>.
*
* @see <a href="https://redis.io/commands/bitfield/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitfield/">valkey.io</a> for details.
* @param key The key of the string.
* @param subCommands The subCommands to be performed on the binary value of the string at <code>
* key</code>, which could be any of the following:
Expand Down Expand Up @@ -4178,10 +4179,11 @@ public T bitfield(@NonNull String key, @NonNull BitFieldSubCommands[] subCommand

/**
* Reads the array of bits representing the string that is held at <code>key</code> based on the
* specified <code>subCommands</code>.
* specified <code>subCommands</code>.<br>
* This command is routed depending on the client's {@link ReadFrom} strategy.
*
* @since Redis 6.0 and above
* @see <a href="https://redis.io/docs/latest/commands/bitfield_ro/">redis.io</a> for details.
* @see <a href="https://valkey.io/commands/bitfield_ro/">valkey.io</a> for details.
* @param key The key of the string.
* @param subCommands The <code>GET</code> subCommands to be performed.
* @return Command Response - An array of results from the <code>GET</code> subcommands.
Expand Down
40 changes: 40 additions & 0 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
import * as net from "net";
import { Buffer, BufferWriter, Reader, Writer } from "protobufjs";
import {
AggregationType,
ExpireOptions,
KeyWeight,
RangeByIndex,
RangeByLex,
RangeByScore,
Expand Down Expand Up @@ -83,6 +85,7 @@ import {
createZAdd,
createZCard,
createZCount,
createZInterstore,
createZPopMax,
createZPopMin,
createZRange,
Expand Down Expand Up @@ -1883,6 +1886,43 @@ export class BaseClient {
);
}

/**
* Computes the intersection of sorted sets given by the specified `keys` and stores the result in `destination`.
* If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.
* To get the result directly, see `zinter_withscores`.
*
* When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot.
*
* See https://valkey.io/commands/zinterstore/ for more details.
*
* @param destination - The key of the destination sorted set.
* @param keys - The keys of the sorted sets with possible formats:
* string[] - for keys only.
* KeyWeight[] - for weighted keys with score multipliers.
* @param aggregationType - Specifies the aggregation strategy to apply when combining the scores of elements. See `AggregationType`.
* @returns The number of elements in the resulting sorted set stored at `destination`.
*
* @example
* ```typescript
* // Example usage of zinterstore command with an existing key
* await client.zadd("key1", {"member1": 10.5, "member2": 8.2})
* await client.zadd("key2", {"member1": 9.5})
* await client.zinterstore("my_sorted_set", ["key1", "key2"]) // Output: 1 - Indicates that the sorted set "my_sorted_set" contains one element.
* await client.zrange_withscores("my_sorted_set", RangeByIndex(0, -1)) // Output: {'member1': 20} - "member1" is now stored in "my_sorted_set" with score of 20.
* await client.zinterstore("my_sorted_set", ["key1", "key2"] , AggregationType.MAX ) // Output: 1 - Indicates that the sorted set "my_sorted_set" contains one element, and it's score is the maximum score between the sets.
* await client.zrange_withscores("my_sorted_set", RangeByIndex(0, -1)) // Output: {'member1': 10.5} - "member1" is now stored in "my_sorted_set" with score of 10.5.
* ```
*/
public zinterstore(
destination: string,
keys: string[] | KeyWeight[],
aggregationType?: AggregationType,
): Promise<number> {
return this.createWritePromise(
createZInterstore(destination, keys, aggregationType),
);
}

/** Returns the length of the string value stored at `key`.
* See https://redis.io/commands/strlen/ for more details.
*
Expand Down
44 changes: 44 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,50 @@ export function createZAdd(
return createCommand(RequestType.ZAdd, args);
}

/**
* `KeyWeight` - pair of variables represents a weighted key for the `ZINTERSTORE` and `ZUNIONSTORE` sorted sets commands.
*/
export type KeyWeight = [string, number];
/**
* `AggregationType` - representing aggregation types for `ZINTERSTORE` and `ZUNIONSTORE` sorted set commands.
*/
export type AggregationType = "SUM" | "MIN" | "MAX";

/**
* @internal
*/
export function createZInterstore(
destination: string,
keys: string[] | KeyWeight[],
aggregationType?: AggregationType,
): redis_request.Command {
const args = createZCmdStoreArgs(destination, keys, aggregationType);
return createCommand(RequestType.ZInterStore, args);
}

function createZCmdStoreArgs(
destination: string,
keys: string[] | KeyWeight[],
aggregationType?: AggregationType,
): string[] {
const args: string[] = [destination, keys.length.toString()];

if (typeof keys[0] === "string") {
args.push(...(keys as string[]));
} else {
const weightsKeys = keys.map(([key]) => key);
args.push(...(weightsKeys as string[]));
const weights = keys.map(([, weight]) => weight.toString());
args.push("WEIGHTS", ...weights);
}

if (aggregationType) {
args.push("AGGREGATE", aggregationType);
}

return args;
}

/**
* @internal
*/
Expand Down
Loading

0 comments on commit 5287e9a

Please sign in to comment.