Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Spring Data and update Lettuce support #8

Merged
merged 4 commits into from
Jan 17, 2024

Conversation

rubengees
Copy link
Member

@rubengees rubengees commented Jan 16, 2024

This adds support for publishing via the RedisTemplate from Spring Data Redis. spring-boot-starter-data-redis is added as a compileOnly dependency and thus is not required by consumers which do not use it.

Additionally, the LettucePublisher now takes RedisCommands instead of a StatefulRedisConnection. That is better from what I understand since that is what you actually are supposed to run api calls on. StatefulRedisConnection is one of multiple options depending on the type of redis instance you are connecting to (there also exists StatefulRedisClusterConnection for example). This is a breaking change but you couldn't use the publisher before anyways since the generics were <Any, Any> which is impossible to satisfy so it should be fine.

Lastly, I added tests for all publishers with a real redis instance using testcontainers.

Copy link
Member

@drosowski drosowski left a comment

Choose a reason for hiding this comment

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

Awesome change! 💯


class LettucePublisher(private val connection: StatefulRedisConnection<Any, Any>) : RedisPublisher {
class LettucePublisher(private val commands: RedisCommands<String, String>) : RedisPublisher {
Copy link
Member

Choose a reason for hiding this comment

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

I'm just wondering if the key/value is always String?

Copy link
Member Author

Choose a reason for hiding this comment

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

For lettuce, the consumer can pass in a Codec that encodes and decodes what is sent to redis. So you could also have e.g. RedisCommands<ByteArray, ByteArray>. When using the instance, we need to know what the types are though so we now what we can send and we request an instance that handles Strings. I think it will be that anyways in almost all cases since all default APIs return that.

* Returns the first message published on the given [channel] of the redis available under the [redisURI]. Waits for at
* most five seconds after executing [body] for the message to arrive.
*/
fun awaitRedisMessage(redisURI: String, channel: String, body: () -> Unit): RedisMessage {
Copy link
Member

Choose a reason for hiding this comment

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

This is great! 🤩

@rubengees rubengees merged commit 8ab7a7e into main Jan 17, 2024
2 checks passed
@rubengees rubengees deleted the spring-data-support branch January 17, 2024 10:06
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.

2 participants