From 81f137fe0e898b95ec6229140a015272b66db694 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 24 Jun 2024 11:01:30 +0000 Subject: [PATCH 1/4] support geodist, getbit, setbit and xack with GlideString --- .../src/main/java/glide/api/BaseClient.java | 40 ++++++ .../api/commands/BitmapBaseCommands.java | 41 ++++++ .../GeospatialIndicesBaseCommands.java | 40 ++++++ .../api/commands/StreamBaseCommands.java | 20 +++ .../test/java/glide/api/RedisClientTest.java | 126 ++++++++++++++++++ 5 files changed, 267 insertions(+) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 7167ba4bff..0ec332dbdd 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -1559,6 +1559,13 @@ public CompletableFuture xack( return commandManager.submitNewCommand(XAck, args, this::handleLongResponse); } + @Override + public CompletableFuture xack( + @NonNull GlideString key, @NonNull GlideString group, @NonNull GlideString[] ids) { + GlideString[] args = concatenateArrays(new GlideString[] {key, group}, ids); + return commandManager.submitNewCommand(XAck, args, this::handleLongResponse); + } + @Override public CompletableFuture pttl(@NonNull String key) { return commandManager.submitNewCommand(PTTL, new String[] {key}, this::handleLongResponse); @@ -1741,6 +1748,17 @@ public CompletableFuture geodist( return commandManager.submitNewCommand(GeoDist, arguments, this::handleDoubleOrNullResponse); } + @Override + public CompletableFuture geodist( + @NonNull GlideString key, + @NonNull GlideString member1, + @NonNull GlideString member2, + @NonNull GeoUnit geoUnit) { + GlideString[] arguments = + new GlideString[] {key, member1, member2, gs(geoUnit.getRedisApi().getBytes())}; + return commandManager.submitNewCommand(GeoDist, arguments, this::handleDoubleOrNullResponse); + } + @Override public CompletableFuture geodist( @NonNull String key, @NonNull String member1, @NonNull String member2) { @@ -1748,6 +1766,13 @@ public CompletableFuture geodist( return commandManager.submitNewCommand(GeoDist, arguments, this::handleDoubleOrNullResponse); } + @Override + public CompletableFuture geodist( + @NonNull GlideString key, @NonNull GlideString member1, @NonNull GlideString member2) { + GlideString[] arguments = new GlideString[] {key, member1, member2}; + return commandManager.submitNewCommand(GeoDist, arguments, this::handleDoubleOrNullResponse); + } + @Override public CompletableFuture geohash(@NonNull String key, @NonNull String[] members) { String[] arguments = concatenateArrays(new String[] {key}, members); @@ -1782,12 +1807,27 @@ public CompletableFuture setbit(@NonNull String key, long offset, long val return commandManager.submitNewCommand(SetBit, arguments, this::handleLongResponse); } + @Override + public CompletableFuture setbit(@NonNull GlideString key, long offset, long value) { + GlideString[] arguments = + new GlideString[] { + key, gs(Long.toString(offset).getBytes()), gs(Long.toString(value).getBytes()) + }; + return commandManager.submitNewCommand(SetBit, arguments, this::handleLongResponse); + } + @Override public CompletableFuture getbit(@NonNull String key, long offset) { String[] arguments = new String[] {key, Long.toString(offset)}; return commandManager.submitNewCommand(GetBit, arguments, this::handleLongResponse); } + @Override + public CompletableFuture getbit(@NonNull GlideString key, long offset) { + GlideString[] arguments = new GlideString[] {key, gs(Long.toString(offset).getBytes())}; + return commandManager.submitNewCommand(GetBit, arguments, this::handleLongResponse); + } + @Override public CompletableFuture bitpos(@NonNull String key, long bit) { String[] arguments = new String[] {key, Long.toString(bit)}; 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 508cff39ca..0ea4909454 100644 --- a/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/BitmapBaseCommands.java @@ -4,6 +4,7 @@ import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldReadOnlySubCommands; import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldSubCommands; +import glide.api.models.GlideString; import glide.api.models.commands.bitmap.BitFieldOptions.BitFieldGet; import glide.api.models.commands.bitmap.BitFieldOptions.BitFieldIncrby; import glide.api.models.commands.bitmap.BitFieldOptions.BitFieldOverflow; @@ -107,6 +108,28 @@ public interface BitmapBaseCommands { */ CompletableFuture setbit(String key, long offset, long value); + /** + * Sets or clears the bit at offset in the string value stored at key. + * The offset is a zero-based index, with 0 being the first element of + * the list, 1 being the next element, and so on. The offset must be + * less than 2^32 and greater than or equal to 0. If a key is + * non-existent then the bit at offset is set to value and the preceding + * bits are set to 0. + * + * @see valkey.io 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 offset. The value must be 0 or + * 1. + * @return The bit value that was previously stored at offset. + * @example + *
{@code
+     * Long payload = client.setbit(gs("myKey1"), 1, 1).get();
+     * assert payload == 0L; // The second bit value was 0 before setting to 1.
+     * }
+ */ + CompletableFuture setbit(GlideString key, long offset, long value); + /** * Returns the bit value at offset in the string value stored at key. * offset should be greater than or equal to zero. @@ -125,6 +148,24 @@ public interface BitmapBaseCommands { */ CompletableFuture getbit(String key, long offset); + /** + * Returns the bit value at offset in the string value stored at key. + * offset should be greater than or equal to zero. + * + * @see valkey.io 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 + * offset exceeds the length of the string. + * @example + *
{@code
+     * client.set(gs("sampleKey"), gs("A")); // "A" has binary value 01000001
+     * Long payload = client.getbit(gs("sampleKey"), 1).get();
+     * assert payload == 1L; // The second bit for string stored at "sampleKey" is set to 1.
+     * }
+ */ + CompletableFuture getbit(GlideString key, long offset); + /** * Returns the position of the first bit matching the given bit value. * diff --git a/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java b/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java index 6517c99704..afe37a59f0 100644 --- a/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java @@ -1,6 +1,7 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.commands; +import glide.api.models.GlideString; import glide.api.models.commands.geospatial.GeoAddOptions; import glide.api.models.commands.geospatial.GeoUnit; import glide.api.models.commands.geospatial.GeospatialData; @@ -99,6 +100,26 @@ CompletableFuture geoadd( */ CompletableFuture geodist(String key, String member1, String member2, GeoUnit geoUnit); + /** + * Returns the distance between member1 and member2 saved in the + * geospatial index stored at key. + * + * @see valkey.io for more details. + * @param key The key of the sorted set. + * @param member1 The name of the first member. + * @param member2 The name of the second member. + * @param geoUnit The unit of distance measurement - see {@link GeoUnit}. + * @return The distance between member1 and member2. If one or both + * members do not exist, or if the key does not exist, returns null. + * @example + *
{@code
+     * Double result = client.geodist("mySortedSet", "Palermo", "Catania", GeoUnit.KILOMETERS).get();
+     * System.out.println(result);
+     * }
+ */ + CompletableFuture geodist( + GlideString key, GlideString member1, GlideString member2, GeoUnit geoUnit); + /** * Returns the distance between member1 and member2 saved in the * geospatial index stored at key. @@ -118,6 +139,25 @@ CompletableFuture geoadd( */ CompletableFuture geodist(String key, String member1, String member2); + /** + * Returns the distance between member1 and member2 saved in the + * geospatial index stored at key. + * + * @see valkey.io for more details. + * @param key The key of the sorted set. + * @param member1 The name of the first member. + * @param member2 The name of the second member. + * @return The distance between member1 and member2. If one or both + * members do not exist, or if the key does not exist, returns null. The default + * unit is {@see GeoUnit#METERS}. + * @example + *
{@code
+     * Double result = client.geodist(gs("mySortedSet"), gs("Palermo"), gs("Catania")).get();
+     * System.out.println(result);
+     * }
+ */ + CompletableFuture geodist(GlideString key, GlideString member1, GlideString member2); + /** * Returns the GeoHash strings representing the positions of all the specified * members in the sorted set stored at key. diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index b49c6472c6..9f64556b15 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1,6 +1,7 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.commands; +import glide.api.models.GlideString; import glide.api.models.commands.stream.StreamAddOptions; import glide.api.models.commands.stream.StreamAddOptions.StreamAddOptionsBuilder; import glide.api.models.commands.stream.StreamGroupOptions; @@ -512,4 +513,23 @@ CompletableFuture>> xreadgroup( * */ CompletableFuture xack(String key, String group, String[] ids); + + /** + * Returns the number of messages that were successfully acknowledged by the consumer group member of a stream. + * This command should be called on a pending message so that such message does not get processed again. + * + * @param key The key of the stream. + * @param group The consumer group name. + * @param ids Stream entry ID to acknowledge and purge messages. + * @return The number of messages that were successfully acknowledged. + * @example + *
{@code
+     * GlideString entryId = client.xadd(gs("mystream"), Map.of(gs("myfield"), gs("mydata")).get();
+     * // read messages from streamId
+     * var readResult = client.xreadgroup(Map.of(gs("mystream"), entryId), gs("mygroup"), gs("my0consumer")).get();
+     * // acknowledge messages on stream
+     * assert 1L == client.xack(gs("mystream"), gs("mygroup"), new GlideString[] {entryId}).get();
+     * 
+ */ + CompletableFuture xack(GlideString key, GlideString group, GlideString[] ids); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index d8e4014504..6b8dac568e 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -4708,6 +4708,32 @@ public void xack_returns_success() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xack_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + GlideString groupName = gs("testGroupName"); + GlideString[] ids = new GlideString[] {gs("testId")}; + GlideString[] arguments = concatenateArrays(new GlideString[] {key, groupName}, ids); + Long mockResult = 1L; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAck), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.xack(key, groupName, ids); + Long payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void type_returns_success() { @@ -5491,6 +5517,32 @@ public void geodist_returns_success() { assertEquals(value, payload); } + @SneakyThrows + @Test + public void geodist_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + GlideString member1 = gs("Catania"); + GlideString member2 = gs("Palermo"); + GlideString[] arguments = new GlideString[] {key, member1, member2}; + Double value = 166274.1516; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(value); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(GeoDist), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.geodist(key, member1, member2); + Double payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(value, payload); + } + @SneakyThrows @Test public void geodist_with_metrics_returns_success() { @@ -5518,6 +5570,34 @@ public void geodist_with_metrics_returns_success() { assertEquals(value, payload); } + @SneakyThrows + @Test + public void geodist_with_metrics_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + GlideString member1 = gs("Catania"); + GlideString member2 = gs("Palermo"); + GeoUnit geoUnit = GeoUnit.KILOMETERS; + GlideString[] arguments = + new GlideString[] {key, member1, member2, gs(GeoUnit.KILOMETERS.getRedisApi().getBytes())}; + Double value = 166.2742; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(value); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(GeoDist), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.geodist(key, member1, member2, geoUnit); + Double payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(value, payload); + } + @SneakyThrows @Test public void functionLoad_returns_success() { @@ -5905,6 +5985,29 @@ public void setbit_returns_success() { assertEquals(value, payload); } + @SneakyThrows + @Test + public void setbit_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + Long value = 1L; + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(value); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(SetBit), eq(new GlideString[] {key, gs("8"), gs("1")}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.setbit(key, 8, 1); + Long payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(value, payload); + } + @SneakyThrows @Test public void blmpop_returns_success() { @@ -5996,6 +6099,29 @@ public void getbit_returns_success() { assertEquals(bit, payload); } + @SneakyThrows + @Test + public void getbit_binary_returns_success() { + // setup + GlideString key = gs("testKey"); + Long bit = 1L; + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(bit); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(GetBit), eq(new GlideString[] {key, gs("8")}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.getbit(key, 8); + Long payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(bit, payload); + } + @SneakyThrows @Test public void bitpos_returns_success() { From 4599f826fe7a09909eef4b432d4943bc02fd0feb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 25 Jun 2024 06:50:47 +0000 Subject: [PATCH 2/4] add to integration tests the use of the API with GlideString parameters --- .../commands/GeospatialIndicesBaseCommands.java | 2 +- .../src/test/java/glide/SharedCommandTests.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java b/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java index afe37a59f0..f752992c75 100644 --- a/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/GeospatialIndicesBaseCommands.java @@ -113,7 +113,7 @@ CompletableFuture geoadd( * members do not exist, or if the key does not exist, returns null. * @example *
{@code
-     * Double result = client.geodist("mySortedSet", "Palermo", "Catania", GeoUnit.KILOMETERS).get();
+     * Double result = client.geodist(gs("mySortedSet"), gs("Palermo"), gs("Catania"), GeoUnit.KILOMETERS).get();
      * System.out.println(result);
      * }
*/ diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 5f5d97ec73..09aca53733 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -3649,7 +3649,7 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl assertNotNull(streamid_3); // xack that streamid_1, and streamid_2 was received - assertEquals(2L, client.xack(key, groupName, new String[] {streamid_1, streamid_2}).get()); + assertEquals(2L, client.xack(gs(key.getBytes()), gs(groupName.getBytes()), new GlideString[] {gs(streamid_1.getBytes()), gs(streamid_2.getBytes())}).get()); // Delete the consumer group and expect 1 pending messages (one was received) assertEquals(0L, client.xgroupDelConsumer(key, groupName, consumerName).get()); @@ -3662,7 +3662,7 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl assertEquals(1, result_3.get(key).size()); // wrong group, so xack streamid_3 returns 0 - assertEquals(0L, client.xack(key, "not_a_group", new String[] {streamid_3}).get()); + assertEquals(0L, client.xack(gs(key.getBytes()), gs("not_a_group"), new GlideString[] {gs(streamid_3.getBytes())}).get()); // Delete the consumer group and expect the pending message assertEquals(1L, client.xgroupDelConsumer(key, groupName, consumerName).get()); @@ -4625,11 +4625,11 @@ public void geodist(BaseClient client) { assertEquals(2, client.geoadd(key1, membersToCoordinates).get()); // assert correct result with default metric - Double actual = client.geodist(key1, member1, member2).get(); + Double actual = client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes())).get(); assertEquals(expected, actual, delta); // assert correct result with manual metric specification kilometers - Double actualKM = client.geodist(key1, member1, member2, geoUnitKM).get(); + Double actualKM = client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes()), geoUnitKM).get(); assertEquals(expectedKM, actualKM, delta); // assert null result when member index is missing @@ -4737,6 +4737,8 @@ public void setbit(BaseClient client) { assertEquals(0, client.setbit(key1, 0, 1).get()); assertEquals(1, client.setbit(key1, 0, 0).get()); + assertEquals(0, client.setbit(gs(key1.getBytes()), 0, 1).get()); + assertEquals(1, client.setbit(gs(key1.getBytes()), 0, 0).get()); // Exception thrown due to the negative offset ExecutionException executionException = @@ -4763,11 +4765,13 @@ public void getbit(BaseClient client) { String key2 = UUID.randomUUID().toString(); String missingKey = UUID.randomUUID().toString(); String value = "foobar"; - assertEquals(OK, client.set(key1, value).get()); assertEquals(1, client.getbit(key1, 1).get()); assertEquals(0, client.getbit(key1, 1000).get()); assertEquals(0, client.getbit(missingKey, 1).get()); + assertEquals(1, client.getbit(gs(key1.getBytes()), 1).get()); + assertEquals(0, client.getbit(gs(key1.getBytes()), 1000).get()); + assertEquals(0, client.getbit(gs(missingKey.getBytes()), 1).get()); if (client instanceof RedisClient) { assertEquals( 1L, ((RedisClient) client).customCommand(new String[] {"SETBIT", key1, "5", "0"}).get()); From 98ca437cc33218435700720116d5b0ae0fd229a9 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 25 Jun 2024 07:09:00 +0000 Subject: [PATCH 3/4] nit: apply spotlessApply --- .../test/java/glide/SharedCommandTests.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 09aca53733..55addbfd97 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -3649,7 +3649,14 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl assertNotNull(streamid_3); // xack that streamid_1, and streamid_2 was received - assertEquals(2L, client.xack(gs(key.getBytes()), gs(groupName.getBytes()), new GlideString[] {gs(streamid_1.getBytes()), gs(streamid_2.getBytes())}).get()); + assertEquals( + 2L, + client + .xack( + gs(key.getBytes()), + gs(groupName.getBytes()), + new GlideString[] {gs(streamid_1.getBytes()), gs(streamid_2.getBytes())}) + .get()); // Delete the consumer group and expect 1 pending messages (one was received) assertEquals(0L, client.xgroupDelConsumer(key, groupName, consumerName).get()); @@ -3662,7 +3669,14 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl assertEquals(1, result_3.get(key).size()); // wrong group, so xack streamid_3 returns 0 - assertEquals(0L, client.xack(gs(key.getBytes()), gs("not_a_group"), new GlideString[] {gs(streamid_3.getBytes())}).get()); + assertEquals( + 0L, + client + .xack( + gs(key.getBytes()), + gs("not_a_group"), + new GlideString[] {gs(streamid_3.getBytes())}) + .get()); // Delete the consumer group and expect the pending message assertEquals(1L, client.xgroupDelConsumer(key, groupName, consumerName).get()); @@ -4625,11 +4639,15 @@ public void geodist(BaseClient client) { assertEquals(2, client.geoadd(key1, membersToCoordinates).get()); // assert correct result with default metric - Double actual = client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes())).get(); + Double actual = + client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes())).get(); assertEquals(expected, actual, delta); // assert correct result with manual metric specification kilometers - Double actualKM = client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes()), geoUnitKM).get(); + Double actualKM = + client + .geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes()), geoUnitKM) + .get(); assertEquals(expectedKM, actualKM, delta); // assert null result when member index is missing From 977b7e6eb4116e8b82c22b83d1d4fb76eaff719a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 25 Jun 2024 07:50:13 +0000 Subject: [PATCH 4/4] remove calls to getBytes() --- .../src/main/java/glide/api/BaseClient.java | 9 ++---- .../test/java/glide/api/RedisClientTest.java | 2 +- .../test/java/glide/SharedCommandTests.java | 31 ++++++------------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 0ec332dbdd..7d21b12915 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -1754,8 +1754,7 @@ public CompletableFuture geodist( @NonNull GlideString member1, @NonNull GlideString member2, @NonNull GeoUnit geoUnit) { - GlideString[] arguments = - new GlideString[] {key, member1, member2, gs(geoUnit.getRedisApi().getBytes())}; + GlideString[] arguments = new GlideString[] {key, member1, member2, gs(geoUnit.getRedisApi())}; return commandManager.submitNewCommand(GeoDist, arguments, this::handleDoubleOrNullResponse); } @@ -1810,9 +1809,7 @@ public CompletableFuture setbit(@NonNull String key, long offset, long val @Override public CompletableFuture setbit(@NonNull GlideString key, long offset, long value) { GlideString[] arguments = - new GlideString[] { - key, gs(Long.toString(offset).getBytes()), gs(Long.toString(value).getBytes()) - }; + new GlideString[] {key, gs(Long.toString(offset)), gs(Long.toString(value))}; return commandManager.submitNewCommand(SetBit, arguments, this::handleLongResponse); } @@ -1824,7 +1821,7 @@ public CompletableFuture getbit(@NonNull String key, long offset) { @Override public CompletableFuture getbit(@NonNull GlideString key, long offset) { - GlideString[] arguments = new GlideString[] {key, gs(Long.toString(offset).getBytes())}; + GlideString[] arguments = new GlideString[] {key, gs(Long.toString(offset))}; return commandManager.submitNewCommand(GetBit, arguments, this::handleLongResponse); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 6b8dac568e..076d804b65 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -5579,7 +5579,7 @@ public void geodist_with_metrics_binary_returns_success() { GlideString member2 = gs("Palermo"); GeoUnit geoUnit = GeoUnit.KILOMETERS; GlideString[] arguments = - new GlideString[] {key, member1, member2, gs(GeoUnit.KILOMETERS.getRedisApi().getBytes())}; + new GlideString[] {key, member1, member2, gs(GeoUnit.KILOMETERS.getRedisApi())}; Double value = 166.2742; CompletableFuture testResponse = new CompletableFuture<>(); diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 55addbfd97..244bdde84b 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -3652,10 +3652,7 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl assertEquals( 2L, client - .xack( - gs(key.getBytes()), - gs(groupName.getBytes()), - new GlideString[] {gs(streamid_1.getBytes()), gs(streamid_2.getBytes())}) + .xack(gs(key), gs(groupName), new GlideString[] {gs(streamid_1), gs(streamid_2)}) .get()); // Delete the consumer group and expect 1 pending messages (one was received) @@ -3670,13 +3667,7 @@ public void xgroupCreateConsumer_xgroupDelConsumer_xreadgroup_xack(BaseClient cl // wrong group, so xack streamid_3 returns 0 assertEquals( - 0L, - client - .xack( - gs(key.getBytes()), - gs("not_a_group"), - new GlideString[] {gs(streamid_3.getBytes())}) - .get()); + 0L, client.xack(gs(key), gs("not_a_group"), new GlideString[] {gs(streamid_3)}).get()); // Delete the consumer group and expect the pending message assertEquals(1L, client.xgroupDelConsumer(key, groupName, consumerName).get()); @@ -4639,15 +4630,11 @@ public void geodist(BaseClient client) { assertEquals(2, client.geoadd(key1, membersToCoordinates).get()); // assert correct result with default metric - Double actual = - client.geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes())).get(); + Double actual = client.geodist(gs(key1), gs(member1), gs(member2)).get(); assertEquals(expected, actual, delta); // assert correct result with manual metric specification kilometers - Double actualKM = - client - .geodist(gs(key1.getBytes()), gs(member1.getBytes()), gs(member2.getBytes()), geoUnitKM) - .get(); + Double actualKM = client.geodist(gs(key1), gs(member1), gs(member2), geoUnitKM).get(); assertEquals(expectedKM, actualKM, delta); // assert null result when member index is missing @@ -4755,8 +4742,8 @@ public void setbit(BaseClient client) { assertEquals(0, client.setbit(key1, 0, 1).get()); assertEquals(1, client.setbit(key1, 0, 0).get()); - assertEquals(0, client.setbit(gs(key1.getBytes()), 0, 1).get()); - assertEquals(1, client.setbit(gs(key1.getBytes()), 0, 0).get()); + assertEquals(0, client.setbit(gs(key1), 0, 1).get()); + assertEquals(1, client.setbit(gs(key1), 0, 0).get()); // Exception thrown due to the negative offset ExecutionException executionException = @@ -4787,9 +4774,9 @@ public void getbit(BaseClient client) { assertEquals(1, client.getbit(key1, 1).get()); assertEquals(0, client.getbit(key1, 1000).get()); assertEquals(0, client.getbit(missingKey, 1).get()); - assertEquals(1, client.getbit(gs(key1.getBytes()), 1).get()); - assertEquals(0, client.getbit(gs(key1.getBytes()), 1000).get()); - assertEquals(0, client.getbit(gs(missingKey.getBytes()), 1).get()); + assertEquals(1, client.getbit(gs(key1), 1).get()); + assertEquals(0, client.getbit(gs(key1), 1000).get()); + assertEquals(0, client.getbit(gs(missingKey), 1).get()); if (client instanceof RedisClient) { assertEquals( 1L, ((RedisClient) client).customCommand(new String[] {"SETBIT", key1, "5", "0"}).get());