Skip to content

Commit

Permalink
Fix issue #5693 - RBatch does not work with randomKeyAsync
Browse files Browse the repository at this point in the history
Signed-off-by: wynn5a <[email protected]>
  • Loading branch information
wynn5a committed Apr 10, 2024
1 parent 5d93ee3 commit 35a8936
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ public <T, R> RFuture<R> readRandomAsync(RedisClient client, Codec codec, RedisC

private <R, T> void retryReadRandomAsync(Codec codec, RedisCommand<T> command, CompletableFuture<R> mainPromise,
List<RedisClient> nodes, Object... params) {
RedisClient entry = nodes.remove(0);
RFuture<R> attemptPromise = async(true, new NodeSource(entry), codec, command, params, false, false);
RedisClient client = nodes.remove(0);
MasterSlaveEntry masterSlaveEntry = connectionManager.getEntry(client);
RFuture<R> attemptPromise = async(true, new NodeSource(masterSlaveEntry, client), codec, command, params, false, false);
attemptPromise.whenComplete((res, e) -> {
if (e == null) {
if (res == null) {
Expand Down
12 changes: 12 additions & 0 deletions redisson/src/test/java/org/redisson/RedissonBatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ public void testConnectionLeak(BatchOptions batchOptions) {
});
}

@Test
public void testBatchReadRandom() throws Exception {
redisson.getMap("key1").put("1", "2");
String randomKey = redisson.getKeys().randomKeyAsync().get();
RBatch batch = redisson.createBatch();
RFuture<String> keys = batch.getKeys().randomKeyAsync();
batch.execute();
String randomKeyInBatch = keys.get();
assertThat(randomKeyInBatch).isNotBlank();
assertThat(randomKeyInBatch).isEqualTo(randomKey);
}

public RFuture<BatchResult<?>> executeBatch(RedissonClient client, BatchOptions batchOptions) {
RBatch batch = client.createBatch(batchOptions);
for (int i = 0; i < 100000; i++) {
Expand Down

0 comments on commit 35a8936

Please sign in to comment.