Skip to content

Conversation

@andy-stark-redis
Copy link
Contributor

@andy-stark-redis andy-stark-redis commented Jun 30, 2025

Make sure that:

  • You have read the contribution guidelines.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

DOC-5399 and DOC-5398.

Lettuce examples for the SADD and SMEMBERS command pages.

@andy-stark-redis andy-stark-redis marked this pull request as ready for review June 30, 2025 15:22
@tishun tishun added this to the Async milestone Aug 5, 2025
Copy link
Contributor

@a-TODO-rov a-TODO-rov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !
Minor comments.


@Test
public void run() {
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RedisClient is AutoClosable and can be put inside try() instead calling shutdown() manually.

// STEP_START sadd
CompletableFuture<Void> sadd = asyncCommands.sadd("myset", "Hello").thenCompose(r -> {
System.out.println(r); // >>> 1
// REMOVE_START
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it sounds dramatic! :-) It just means that this line shouldn't appear in the published example on the docs page (we avoid showing the users the asserts that we test the examples with).

.toCompletableFuture();
// STEP_END
// HIDE_START
sadd.join();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead joins i would prefer the approach with CompletableFuture.allOf() like in HashExample

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We originally did this to avoid the code snippets getting executed out-of-order during testing (some of them use results from previous snippets and so tests fail if a snippet executes before another snippet that it depends on). If this is no longer a problem, or doesn't apply in this case then I'll use allOf, as you suggest.

TBH, we might have to revisit this stuff carefully now we've got Jupyter notebooks for some of the examples (via the "Run in browser" link). Dependencies between the cells can be a problem with the notebooks too.

// REMOVE_START
// Clean up any existing data
Mono<Void> cleanup = reactiveCommands.del("myset").then();
cleanup.block();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in async we can wrap the block operations in Mono.when()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was the out-of-order execution during testing again, but as I said for async, I'll certainly change this if it's not a problem here.

})
// REMOVE_START
.thenApply(r -> {
assertThat(r.stream().sorted().collect(toList()).toString()).isEqualTo("[Hello, World]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced with assertThat(r).containsExactlyInAnyOrder("Hello", "World")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a great tip, thanks! The streams thing borrows from what we were doing with the Jedis examples, but your suggestion is much neater :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants