Skip to content

Commit

Permalink
fix tests & transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Shoham Elias <shohame@amazon.com>
  • Loading branch information
shohamazon committed Sep 10, 2024
1 parent a3e2455 commit 686647c
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 160 deletions.
22 changes: 11 additions & 11 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -12637,14 +12637,14 @@ public void sort_with_pattern_binary(BaseClient client) {
assumeTrue(SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0"), "This feature added in version 8");
}

GlideString setKey1 = gs("{setKey}1");
GlideString setKey2 = gs("{setKey}2");
GlideString setKey3 = gs("{setKey}3");
GlideString setKey4 = gs("{setKey}4");
GlideString setKey5 = gs("{setKey}5");
GlideString setKey1 = gs("{setKeyGs}1");
GlideString setKey2 = gs("{setKeyGs}2");
GlideString setKey3 = gs("{setKeyGs}3");
GlideString setKey4 = gs("{setKeyGs}4");
GlideString setKey5 = gs("{setKeyGs}5");
GlideString[] setKeys = new GlideString[] {setKey1, setKey2, setKey3, setKey4, setKey5};
GlideString listKey = gs("{setKey}listKey");
GlideString storeKey = gs("{setKey}storeKey");
GlideString listKey = gs("{setKeyGs}listKey");
GlideString storeKey = gs("{setKeyGs}storeKey");
GlideString nameField = gs("name");
GlideString ageField = gs("age");
GlideString[] names =
Expand All @@ -12654,8 +12654,8 @@ public void sort_with_pattern_binary(BaseClient client) {
new GlideString[] {gs("Dave"), gs("Bob"), gs("Alice"), gs("Charlie"), gs("Eve")};
GlideString[] ages = new GlideString[] {gs("30"), gs("25"), gs("35"), gs("20"), gs("40")};
GlideString[] userIDs = new GlideString[] {gs("3"), gs("1"), gs("5"), gs("4"), gs("2")};
GlideString namePattern = gs("{setKey}*->name");
GlideString agePattern = gs("{setKey}*->age");
GlideString namePattern = gs("{setKeyGs}*->name");
GlideString agePattern = gs("{setKeyGs}*->age");
GlideString missingListKey = gs("100000");

for (int i = 0; i < setKeys.length; i++) {
Expand Down Expand Up @@ -12719,7 +12719,7 @@ public void sort_with_pattern_binary(BaseClient client) {
client
.sort(
listKey,
SortOptionsBinary.builder().alpha().getPattern(gs("{setKey}missing")).build())
SortOptionsBinary.builder().alpha().getPattern(gs("{setKeyGs}missing")).build())
.get());

// Missing key in the set
Expand Down Expand Up @@ -12782,7 +12782,7 @@ public void sort_with_pattern_binary(BaseClient client) {
client
.sortReadOnly(
listKey,
SortOptionsBinary.builder().alpha().getPattern(gs("{setKey}missing")).build())
SortOptionsBinary.builder().alpha().getPattern(gs("{setKeyGs}missing")).build())
.get());

assertArrayEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,16 @@ public void spublish() {
@Test
@SneakyThrows
public void sort() {
String key1 = "{key}-1" + UUID.randomUUID();
String key2 = "{key}-2" + UUID.randomUUID();
String key1 = "{key}:1" + UUID.randomUUID();
String key2 = "{key}:2" + UUID.randomUUID();
String key3 = "{key}:3";
String key4 = "{key}:4";
String key5 = "{key}:5" + UUID.randomUUID();
String key6 = "{key}:6" + UUID.randomUUID();
String[] descendingList = new String[] {"3", "2", "1"};
ClusterTransaction transaction = new ClusterTransaction();
String[] ascendingListByAge = new String[] {"Bob", "Alice"};
String[] descendingListByAge = new String[] {"Alice", "Bob"};
transaction
.lpush(key1, new String[] {"3", "1", "2"})
.sort(key1, SortOptions.builder().orderBy(DESC).build())
Expand All @@ -305,6 +311,37 @@ public void sort() {
transaction.sortReadOnly(key1, SortOptions.builder().orderBy(DESC).build());
}

if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) {
transaction
.hset(key3, Map.of("name", "Alice", "age", "30"))
.hset(key4, Map.of("name", "Bob", "age", "25"))
.lpush(key5, new String[] {"4", "3"})
.sort(
key5,
SortOptions.builder().byPattern("{key}:*->age").getPattern("{key}:*->name").build())
.sort(
key5,
SortOptions.builder()
.orderBy(DESC)
.byPattern("{key}:*->age")
.getPattern("{key}:*->name")
.build())
.sortStore(
key5,
key6,
SortOptions.builder().byPattern("{key}:*->age").getPattern("{key}:*->name").build())
.lrange(key6, 0, -1)
.sortStore(
key5,
key6,
SortOptions.builder()
.orderBy(DESC)
.byPattern("{key}:*->age")
.getPattern("{key}:*->name")
.build())
.lrange(key6, 0, -1);
}

Object[] results = clusterClient.exec(transaction).get();
Object[] expectedResult =
new Object[] {
Expand All @@ -321,6 +358,23 @@ public void sort() {
);
}

if (SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")) {
expectedResult =
concatenateArrays(
expectedResult,
new Object[] {
2L, // hset(key3, Map.of("name", "Alice", "age", "30"))
2L, // hset(key4, Map.of("name", "Bob", "age", "25"))
2L, // lpush(key5, new String[] {"4", "3"})
ascendingListByAge, // sort(key5, SortOptions)
descendingListByAge, // sort(key5, SortOptions)
2L, // sortStore(key5, ksy6, SortOptions)
ascendingListByAge, // lrange(key6, 0, -1)
2L, // sortStore(key5, ksy6, SortOptions)
descendingListByAge, // lrange(key6, 0, -1)
});
}

assertDeepEquals(expectedResult, results);
}

Expand Down
6 changes: 3 additions & 3 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6772,7 +6772,7 @@ async def sort(
To store the result into a new key, see `sort_store`.
Note: When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
must hash to the same slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
only since Valkey version 8.0.
See https://valkey.io/commands/sort for more details.
Expand Down Expand Up @@ -6843,7 +6843,7 @@ async def sort_ro(
See https://valkey.io/commands/sort for more details.
Note: When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
must hash to the same slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
only since Valkey version 8.0.
Args:
Expand Down Expand Up @@ -6915,7 +6915,7 @@ async def sort_store(
See https://valkey.io/commands/sort for more details.
Note: When in cluster mode, `key`, `destination`, and any patterns specified in `by_pattern` or `get_patterns`
must hash to the same slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
only since Valkey version 8.0.
Args:
Expand Down
1 change: 0 additions & 1 deletion python/python/glide/async_commands/standalone_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ async def move(self, key: TEncodable, db_index: int) -> bool:
await self._execute_command(RequestType.Move, [key, str(db_index)]),
)


async def publish(self, message: TEncodable, channel: TEncodable) -> int:
"""
Publish a message on pubsub channel.
Expand Down
Loading

0 comments on commit 686647c

Please sign in to comment.