From 93cb033fb0c98273e2f12f0d3aa8aa10d806a031 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 8 Sep 2024 10:19:03 +0000 Subject: [PATCH 1/7] Valkey-8: change bitpos end param to optional Signed-off-by: Shoham Elias --- .../src/main/java/glide/api/BaseClient.java | 12 +++++ .../api/commands/BitmapBaseCommands.java | 42 +++++++++++++++++ .../glide/api/models/BaseTransaction.java | 20 +++++++++ .../test/java/glide/api/GlideClientTest.java | 45 +++++++++++++++++++ .../glide/api/models/TransactionTests.java | 3 ++ .../test/java/glide/SharedCommandTests.java | 18 ++++++++ .../java/glide/TransactionTestUtilities.java | 13 ++++++ node/src/BaseClient.ts | 1 + node/src/Commands.ts | 8 ++-- node/tests/SharedTests.ts | 36 +++++++++++++++ node/tests/TestUtilities.ts | 9 ++++ python/python/glide/async_commands/bitmap.py | 11 +++-- python/python/glide/async_commands/core.py | 2 + python/python/tests/test_async_client.py | 19 ++++++++ python/python/tests/test_transaction.py | 6 +++ 15 files changed, 239 insertions(+), 6 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 0638201f9e..a6294e1c0c 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -3844,6 +3844,18 @@ public CompletableFuture bitcount(@NonNull GlideString key) { BitCount, new GlideString[] {key}, this::handleLongResponse); } + @Override + public CompletableFuture bitcount(@NonNull String key, long start) { + return commandManager.submitNewCommand( + BitCount, new String[] {key, Long.toString(start)}, this::handleLongResponse); + } + + @Override + public CompletableFuture bitcount(@NonNull GlideString key, long start) { + return commandManager.submitNewCommand( + BitCount, new GlideString[] {key, gs(Long.toString(start))}, this::handleLongResponse); + } + @Override public CompletableFuture bitcount(@NonNull String key, long start, long end) { return commandManager.submitNewCommand( diff --git a/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java b/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java index 22612c9bd5..24ce34e883 100644 --- a/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java @@ -53,6 +53,48 @@ public interface BitmapBaseCommands { */ CompletableFuture bitcount(GlideString key); + /** + * Counts the number of set bits (population counting) in a string stored at key. The + * offset start is a zero-based index, with 0 being the first byte of + * the list, 1 being the next byte and so on. This offset can also be a negative + * number indicating offsets starting at the end of the list, with -1 being the last + * byte of the list, -2 being the penultimate, and so on. + * + * @since Valkey 8.0 and above + * @see valkey.io for details. + * @param key The key for the string to count the set bits of. + * @param start The starting offset byte index. + * @return The number of set bits in the string byte interval specified by start to + * the last byte. Returns zero if the key is missing as it is treated as an empty string. + * @example + *
{@code
+     * Long payload = client.bitcount("myKey1", 1).get();
+     * assert payload == 2L; // From the second to the last bytes of the string stored at "myKey1" are 2 set bits.
+     * }
+ */ + CompletableFuture bitcount(String key, long start); + + /** + * Counts the number of set bits (population counting) in a string stored at key. The + * offset start is a zero-based index, with 0 being the first byte of + * the list, 1 being the next byte and so on. This offset can also be a negative + * number indicating offsets starting at the end of the list, with -1 being the last + * byte of the list, -2 being the penultimate, and so on. + * + * @since Valkey 8.0 and above + * @see valkey.io for details. + * @param key The key for the string to count the set bits of. + * @param start The starting offset byte index. + * @return The number of set bits in the string byte interval specified by start to + * the last byte. Returns zero if the key is missing as it is treated as an empty string. + * @example + *
{@code
+     * Long payload = client.bitcount(gs("myKey1"), 1).get();
+     * assert payload == 2L; // From the second to the last bytes of the string stored at "myKey1" are 2 set bits.
+     * }
+ */ + CompletableFuture bitcount(GlideString key, long start); + /** * Counts the number of set bits (population counting) in a string stored at key. The * offsets start and end are zero-based indexes, with 0 diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index ecbb9fac70..d3ee0fe571 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -5301,6 +5301,26 @@ public T bitcount(@NonNull ArgType key) { return getThis(); } + /** + * Counts the number of set bits (population counting) in a string stored at key. The + * offset start is a zero-based index, with 0 being the first byte of + * the list, 1 being the next byte and so on. This offset can also be a negative + * number indicating offsets starting at the end of the list, with -1 being the last + * byte of the list, -2 being the penultimate, and so on. + * + * @see valkey.io for details. + * @param key The key for the string to count the set bits of. + * @param start The starting offset byte index. + * @return Command Response - The number of set bits in the string byte interval specified by + * start to the last byte. Returns zero if the key is missing as it is treated as + * an empty string. + */ + public T bitcount(@NonNull ArgType key, long start) { + checkTypeOrThrow(key); + protobufTransaction.addCommands(buildCommand(BitCount, newArgsBuilder().add(key).add(start))); + return getThis(); + } + /** * Counts the number of set bits (population counting) in a string stored at key. The * offsets start and end are zero-based indexes, with 0 diff --git a/java/client/src/test/java/glide/api/GlideClientTest.java b/java/client/src/test/java/glide/api/GlideClientTest.java index 2170218b36..37238ff997 100644 --- a/java/client/src/test/java/glide/api/GlideClientTest.java +++ b/java/client/src/test/java/glide/api/GlideClientTest.java @@ -11643,6 +11643,51 @@ public void bitcount_binary_returns_success() { assertEquals(bitcount, payload); } + @SneakyThrows + @Test + public void bitcount_start_returns_success() { + // setup + String key = "testKey"; + Long bitcount = 1L; + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(bitcount); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(BitCount), eq(new String[] {key, "1"}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.bitcount(key, 1); + Long payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(bitcount, payload); + } + + @SneakyThrows + @Test + public void bitcount_start_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + Long bitcount = 1L; + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(bitcount); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(BitCount), eq(new GlideString[] {key, gs("1")}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.bitcount(key, 1); + Long payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(bitcount, payload); + } + @SneakyThrows @Test public void bitcount_indices_returns_success() { diff --git a/java/client/src/test/java/glide/api/models/TransactionTests.java b/java/client/src/test/java/glide/api/models/TransactionTests.java index c112ff7599..80dbfecb27 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -1172,6 +1172,9 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), transaction.bitcount("key"); results.add(Pair.of(BitCount, buildArgs("key"))); + transaction.bitcount("key", 1); + results.add(Pair.of(BitCount, buildArgs("key", "1"))); + transaction.bitcount("key", 1, 1); results.add(Pair.of(BitCount, buildArgs("key", "1", "1"))); diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 06be6cea3c..b0d04b62da 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -10309,6 +10309,24 @@ public void bitcount(BaseClient client) { () -> client.bitcount(key1, 5, 30, BitmapIndexType.BIT).get()); assertTrue(executionException.getCause() instanceof RequestException); } + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { + assertEquals(26L, client.bitcount(key1, 0).get()); + assertEquals(4L, client.bitcount(key1, 5).get()); + assertEquals(0L, client.bitcount(key1, 80).get()); + assertEquals(7L, client.bitcount(key1, -2).get()); + assertEquals(0, client.bitcount(missingKey, 5).get()); + + // Exception thrown due to the key holding a value with the wrong type + executionException = + assertThrows(ExecutionException.class, () -> client.bitcount(key2, 1).get()); + assertTrue(executionException.getCause() instanceof RequestException); + + } else { + // Exception thrown because optional end was implemented after 8.0.0 + executionException = + assertThrows(ExecutionException.class, () -> client.bitcount(key1, 5).get()); + assertTrue(executionException.getCause() instanceof RequestException); + } } @SneakyThrows diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 4e41fb2751..07e9a5b252 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -1288,6 +1288,10 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { .bitpos(key3, 1, 44, 50, BitmapIndexType.BIT); } + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { + transaction.set(key3, "foobar").bitcount(key3, 1); + } + var expectedResults = new Object[] { OK, // set(key1, "foobar") @@ -1315,6 +1319,15 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { 46L, // bitpos(key, 1, 44, 50, BitmapIndexType.BIT) }); } + + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + return concatenateArrays( + expectedResults, + new Object[] { + OK, // set(key1, "foobar") + 26L, // bitcount(key, 1) + }); + } return expectedResults; } diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 8b394586a4..b48731e862 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -6109,6 +6109,7 @@ export class BaseClient { * @example * ```typescript * console.log(await client.bitcount("my_key1")); // Output: 2 - The string stored at "my_key1" contains 2 set bits. + * console.log(await client.bitcount("my_key2", { start: 1 })); // Output: 8 - From the second to to the last bytes of the string stored at "my_key2" are contain 8 set bits. * console.log(await client.bitcount("my_key2", { start: 1, end: 3 })); // Output: 2 - The second to fourth bytes of the string stored at "my_key2" contain 2 set bits. * console.log(await client.bitcount("my_key3", { start: 1, end: 1, indexType: BitmapIndexType.BIT })); // Output: 1 - Indicates that the second bit of the string stored at "my_key3" is set. * console.log(await client.bitcount("my_key3", { start: -1, end: -1, indexType: BitmapIndexType.BIT })); // Output: 1 - Indicates that the last bit of the string stored at "my_key3" is set. diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 2d26178332..b6ecc312c5 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -2442,8 +2442,10 @@ export function createFunctionRestore( export type BitOffsetOptions = { /** The starting offset index. */ start: number; - /** The ending offset index. */ - end: number; + /** The ending offset index. Optional since Valkey version 8.0 and above. + * If not provided, it will default to the end of the string + */ + end?: number; /** * The index offset type. This option can only be specified if you are using server version 7.0.0 or above. * Could be either {@link BitmapIndexType.BYTE} or {@link BitmapIndexType.BIT}. @@ -2463,7 +2465,7 @@ export function createBitCount( if (options) { args.push(options.start.toString()); - args.push(options.end.toString()); + if (options.end) options.end.toString(); if (options.indexType) args.push(options.indexType); } diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 28cd31d95b..abce721213 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -8516,6 +8516,42 @@ export function runBaseTests(config: { }), ).rejects.toThrow(RequestError); } + + if (cluster.checkIfServerVersionLessThan("7.9.0")) { + await expect( + client.bitcount(key1, { + start: 2, + }), + ).rejects.toThrow(); + } else { + expect( + await client.bitcount(key1, { + start: 1, + }), + ).toEqual(26); + expect( + await client.bitcount(key1, { + start: 5, + }), + ).toEqual(4); + expect( + await client.bitcount(key1, { + start: 80, + }), + ).toEqual(0); + expect( + await client.bitcount(uuidv4(), { + start: 80, + }), + ).toEqual(0); + + // key exists, but it is not a string + await expect( + client.bitcount(key2, { + start: 1, + }), + ).rejects.toThrow(RequestError); + } }, protocol); }, config.timeout, diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 5bfbae0013..9fd94ed582 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -1370,6 +1370,15 @@ export async function transactionTest( ]); } + if (gte(version, "7.9.0")) { + baseTransaction.set(key17, "foobar"); + responseData.push(['set(key17, "foobar")', "OK"]); + baseTransaction.bitcount(key17, { + start: 1, + }); + responseData.push(["bitcount(key17, {start:1 }", 26]); + } + baseTransaction.bitfield(key17, [ new BitFieldSet( new UnsignedEncoding(10), diff --git a/python/python/glide/async_commands/bitmap.py b/python/python/glide/async_commands/bitmap.py index 46fdf61c70..87e501dfb5 100644 --- a/python/python/glide/async_commands/bitmap.py +++ b/python/python/glide/async_commands/bitmap.py @@ -24,7 +24,10 @@ class BitmapIndexType(Enum): class OffsetOptions: def __init__( - self, start: int, end: int, index_type: Optional[BitmapIndexType] = None + self, + start: int, + end: Optional[int] = None, + index_type: Optional[BitmapIndexType] = None, ): """ Represents offsets specifying a string interval to analyze in the `BITCOUNT` command. The offsets are @@ -34,7 +37,7 @@ def __init__( Args: start (int): The starting offset index. - end (int): The ending offset index. + end (int): The ending offset index. Optional since Valkey version 8.0.0 and above. If not provided, it will default to the end of the string. index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are using Valkey version 7.0.0 or above. Could be either `BitmapIndexType.BYTE` or `BitmapIndexType.BIT`. If no index type is provided, the indexes will be assumed to be byte indexes. @@ -44,7 +47,9 @@ def __init__( self.index_type = index_type def to_args(self) -> List[str]: - args = [str(self.start), str(self.end)] + args = [str(self.start)] + if self.end: + args.append(str(self.end)) if self.index_type is not None: args.append(self.index_type.value) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index ba8fd51f74..65d4d1c693 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -5531,6 +5531,8 @@ async def bitcount( Examples: >>> await client.bitcount("my_key1") 2 # The string stored at "my_key1" contains 2 set bits. + >>> await client.bitcount("my_key2", OffsetOptions(1)) + 8 # From the second to last bytes of the string stored at "my_key2" there are 8 set bits. >>> await client.bitcount("my_key2", OffsetOptions(1, 3)) 2 # The second to fourth bytes of the string stored at "my_key2" contain 2 set bits. >>> await client.bitcount("my_key3", OffsetOptions(1, 1, BitmapIndexType.BIT)) diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 9e3664ba08..86a8ceef7c 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -7148,6 +7148,25 @@ async def test_bitcount(self, glide_client: TGlideClient): set_key, OffsetOptions(1, 1, BitmapIndexType.BIT) ) + if await check_if_server_version_lt(glide_client, "7.9.0"): + # exception thrown because BIT and BYTE options were implemented after 8.0.0 + with pytest.raises(RequestError): + await glide_client.bitcount( + key1, + OffsetOptions( + 2, + ), + ) + else: + assert await glide_client.bitcount(key1, OffsetOptions(1)) == 26 + assert await glide_client.bitcount(key1, OffsetOptions(5)) == 4 + assert await glide_client.bitcount(key1, OffsetOptions(80)) == 0 + assert await glide_client.bitcount(non_existing_key, OffsetOptions(5)) == 0 + + # key exists but it is not a string + with pytest.raises(RequestError): + await glide_client.bitcount(set_key, OffsetOptions(1)) + @pytest.mark.parametrize("cluster_mode", [True, False]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_setbit(self, glide_client: TGlideClient): diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 964b1309a9..03b65a1996 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -559,6 +559,12 @@ async def transaction_test( transaction.bitpos_interval(key20, 1, 44, 50, BitmapIndexType.BIT) args.append(46) + if not await check_if_server_version_lt(glide_client, "7.9.0"): + transaction.set(key20, "foobar") + args.append(OK) + transaction.bitcount(key20, OffsetOptions(5, 1)) + args.append(26) + transaction.geoadd( key12, { From f2034b4c5b41f0ad2f4d9f40040207d5c42dcab7 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 8 Sep 2024 10:34:15 +0000 Subject: [PATCH 2/7] fix tests Signed-off-by: Shoham Elias --- .../src/test/java/glide/TransactionTestUtilities.java | 4 ++-- node/tests/SharedTests.ts | 2 +- node/tests/TestUtilities.ts | 4 ++-- python/python/tests/test_async_client.py | 4 ++-- python/python/tests/test_transaction.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 07e9a5b252..2cc4fcec4a 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -1289,7 +1289,7 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { } if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { - transaction.set(key3, "foobar").bitcount(key3, 1); + transaction.set(key3, "foobar").bitcount(key3, 0); } var expectedResults = @@ -1325,7 +1325,7 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { expectedResults, new Object[] { OK, // set(key1, "foobar") - 26L, // bitcount(key, 1) + 26L, // bitcount(key, 0) }); } return expectedResults; diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index abce721213..d20a01cc2e 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -8526,7 +8526,7 @@ export function runBaseTests(config: { } else { expect( await client.bitcount(key1, { - start: 1, + start: 0, }), ).toEqual(26); expect( diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 9fd94ed582..876e40e951 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -1374,9 +1374,9 @@ export async function transactionTest( baseTransaction.set(key17, "foobar"); responseData.push(['set(key17, "foobar")', "OK"]); baseTransaction.bitcount(key17, { - start: 1, + start: 0, }); - responseData.push(["bitcount(key17, {start:1 }", 26]); + responseData.push(["bitcount(key17, {start:0 }", 26]); } baseTransaction.bitfield(key17, [ diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 86a8ceef7c..c650dff75d 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -7149,7 +7149,7 @@ async def test_bitcount(self, glide_client: TGlideClient): ) if await check_if_server_version_lt(glide_client, "7.9.0"): - # exception thrown because BIT and BYTE options were implemented after 8.0.0 + # exception thrown optional end was implemented after 8.0.0 with pytest.raises(RequestError): await glide_client.bitcount( key1, @@ -7158,7 +7158,7 @@ async def test_bitcount(self, glide_client: TGlideClient): ), ) else: - assert await glide_client.bitcount(key1, OffsetOptions(1)) == 26 + assert await glide_client.bitcount(key1, OffsetOptions(0)) == 26 assert await glide_client.bitcount(key1, OffsetOptions(5)) == 4 assert await glide_client.bitcount(key1, OffsetOptions(80)) == 0 assert await glide_client.bitcount(non_existing_key, OffsetOptions(5)) == 0 diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 03b65a1996..4e6a5836a2 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -562,7 +562,7 @@ async def transaction_test( if not await check_if_server_version_lt(glide_client, "7.9.0"): transaction.set(key20, "foobar") args.append(OK) - transaction.bitcount(key20, OffsetOptions(5, 1)) + transaction.bitcount(key20, OffsetOptions(0)) args.append(26) transaction.geoadd( From 1c643130f8b9e54cef2c8000fedfb95efc389871 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 8 Sep 2024 11:01:30 +0000 Subject: [PATCH 3/7] fix version check Signed-off-by: Shoham Elias --- .../integTest/src/test/java/glide/TransactionTestUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 2cc4fcec4a..d1b0fcde40 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -1320,7 +1320,7 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { }); } - if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { return concatenateArrays( expectedResults, new Object[] { From f11e86855f54ca97c6d8258731462e56bd41f072 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 8 Sep 2024 11:57:06 +0000 Subject: [PATCH 4/7] fix test Signed-off-by: Shoham Elias --- .../java/glide/TransactionTestUtilities.java | 30 ++++++++++--------- node/src/Commands.ts | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index d1b0fcde40..c9158aa90f 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -1289,7 +1289,7 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { } if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { - transaction.set(key3, "foobar").bitcount(key3, 0); + transaction.set(key4, "foobar").bitcount(key4, 0); } var expectedResults = @@ -1311,22 +1311,24 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { }; if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { - return concatenateArrays( - expectedResults, - new Object[] { - OK, // set(key1, "foobar") - 17L, // bitcount(key, 5, 30, BitmapIndexType.BIT) - 46L, // bitpos(key, 1, 44, 50, BitmapIndexType.BIT) - }); + expectedResults = + concatenateArrays( + expectedResults, + new Object[] { + OK, // set(key1, "foobar") + 17L, // bitcount(key, 5, 30, BitmapIndexType.BIT) + 46L, // bitpos(key, 1, 44, 50, BitmapIndexType.BIT) + }); } if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) { - return concatenateArrays( - expectedResults, - new Object[] { - OK, // set(key1, "foobar") - 26L, // bitcount(key, 0) - }); + expectedResults = + concatenateArrays( + expectedResults, + new Object[] { + OK, // set(key1, "foobar") + 26L, // bitcount(key, 0) + }); } return expectedResults; } diff --git a/node/src/Commands.ts b/node/src/Commands.ts index b6ecc312c5..e11edfd58b 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -2465,7 +2465,7 @@ export function createBitCount( if (options) { args.push(options.start.toString()); - if (options.end) options.end.toString(); + if (options.end) args.push(options.end.toString()); if (options.indexType) args.push(options.indexType); } From 227f25f7063c231669a9dc7f96e7497e46661153 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:06:52 +0300 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Andrew Carbonetto Co-authored-by: Yury-Fridlyand Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- .../src/test/java/glide/TransactionTestUtilities.java | 10 +++++----- node/src/Commands.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index c9158aa90f..30675fcc56 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -1315,9 +1315,9 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { concatenateArrays( expectedResults, new Object[] { - OK, // set(key1, "foobar") - 17L, // bitcount(key, 5, 30, BitmapIndexType.BIT) - 46L, // bitpos(key, 1, 44, 50, BitmapIndexType.BIT) + OK, // set(key3, "foobar") + 17L, // bitcount(key3, 5, 30, BitmapIndexType.BIT) + 46L, // bitpos(key3, 1, 44, 50, BitmapIndexType.BIT) }); } @@ -1326,8 +1326,8 @@ private static Object[] bitmapCommands(BaseTransaction transaction) { concatenateArrays( expectedResults, new Object[] { - OK, // set(key1, "foobar") - 26L, // bitcount(key, 0) + OK, // set(key4, "foobar") + 26L, // bitcount(key4, 0) }); } return expectedResults; diff --git a/node/src/Commands.ts b/node/src/Commands.ts index e11edfd58b..202ef082c8 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -2465,7 +2465,7 @@ export function createBitCount( if (options) { args.push(options.start.toString()); - if (options.end) args.push(options.end.toString()); + if (options.end !== undefined) args.push(options.end.toString()); if (options.indexType) args.push(options.indexType); } From 534845235e6c39eff47338f1e01b5d9ce7d760cb Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Mon, 9 Sep 2024 17:10:04 +0000 Subject: [PATCH 6/7] add changelog Signed-off-by: Shoham Elias --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 655939fdd3..8216935c52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,12 +96,14 @@ * Node: Added XGROUP CREATE & XGROUP DESTROY commands ([#2084](https://github.com/valkey-io/valkey-glide/pull/2084)) * Node: Added BZPOPMAX & BZPOPMIN command ([#2077](https://github.com/valkey-io/valkey-glide/pull/2077)) * Node: Added XGROUP CREATECONSUMER & XGROUP DELCONSUMER commands ([#2088](https://github.com/valkey-io/valkey-glide/pull/2088)) -* Node: Added GETEX command ([#2107]((https://github.com/valkey-io/valkey-glide/pull/2107)) +* Node: Added GETEX command ([#2107](https://github.com/valkey-io/valkey-glide/pull/2107)) * Node: Added ZINTER and ZUNION commands ([#2146](https://github.com/aws/glide-for-redis/pull/2146)) * Node: Added XACK commands ([#2112](https://github.com/valkey-io/valkey-glide/pull/2112)) -* Node: Added XGROUP SETID command ([#2135]((https://github.com/valkey-io/valkey-glide/pull/2135)) +* Node: Added XGROUP SETID command ([#2135](https://github.com/valkey-io/valkey-glide/pull/2135)) * Node: Added binary variant to string commands ([#2183](https://github.com/valkey-io/valkey-glide/pull/2183)) * Node: Added binary variant to stream commands ([#2200](https://github.com/valkey-io/valkey-glide/pull/2200), [#2222](https://github.com/valkey-io/valkey-glide/pull/2222)) +* Python, Node, Java: change BITCOUNT end param to optional ([#2248](https://github.com/valkey-io/valkey-glide/pull/2248)) + #### Breaking Changes * Node: (Refactor) Convert classes to types ([#2005](https://github.com/valkey-io/valkey-glide/pull/2005)) From bda5f49363c7ea3bf34ae5a614c718d0e27da3a5 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:11:51 +0300 Subject: [PATCH 7/7] Apply suggestions from code review Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9613274f42..846d44167f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,7 +102,6 @@ * Node: Added BZPOPMAX & BZPOPMIN command ([#2077](https://github.com/valkey-io/valkey-glide/pull/2077)) * Node: Added XGROUP CREATECONSUMER & XGROUP DELCONSUMER commands ([#2088](https://github.com/valkey-io/valkey-glide/pull/2088)) * Node: Added GETEX command ([#2107](https://github.com/valkey-io/valkey-glide/pull/2107)) -* Node: Added ZINTER and ZUNION commands ([#2146](https://github.com/aws/glide-for-redis/pull/2146)) * Node: Added ZINTER and ZUNION commands ([#2146](https://github.com/valkey-io/valkey-glide/pull/2146)) * Node: Added XACK commands ([#2112](https://github.com/valkey-io/valkey-glide/pull/2112)) * Node: Added XGROUP SETID command ([#2135](https://github.com/valkey-io/valkey-glide/pull/2135))