-
I'm attempting to broadcast commands to all the replicas in a Redis Cluster deployment, but I'm seeing some weird behavior. Code is below. Redis 6.0.9 and Lettuce 6.1.5. fun doThing(): CompletableFuture<List<Any?>?> {
return lettuce.connectAsync().thenComposeAsync {
it.async().replicas().commands().slowlogGet(1)
}.thenApply {
it
}
}
fun doThing2(): CompletableFuture<List<Any?>?> {
return lettuce.connectAsync().thenComposeAsync {
it.async().replicas().commands().dispatch(
CommandType.SLOWLOG,
NestedMultiOutput(lettuce.codec),
CommandArgs(lettuce.codec).add("GET").add(1)
)
}.thenApply {
it
}
}
fun doThing3(): CompletableFuture<List<Any?>?> {
return lettuce.connectAsync().thenComposeAsync { conn ->
val futures = conn.async().replicas().asMap().values.map {
it.dispatch(
CommandType.SLOWLOG,
NestedMultiOutput(lettuce.codec),
CommandArgs(lettuce.codec).add("GET").add(1)
)
}
CompletableFuture.allOf(*futures.toArray { arrayOfNulls<CompletableFuture<*>>(it) })
.thenApply { futures }
}.thenApply {
it.map { it.get() }
}
}
While 3 does work, (specifically for custom commands), I'm curious as to what option 1 is doing to synchronize the responses properly, why option 2 is not equivalent to 1, and if it's doing it faster than my mess of Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for bringing this up. The NodeSelection API abstracts the selection of nodes and the triggering of individual commands meaning that each connection receives its individual I think we need to do something about it, specifically throw an exception that this method cannot be used and we need to document that behavior. Instead, we could introduce a |
Beta Was this translation helpful? Give feedback.
Thanks for bringing this up. The NodeSelection API abstracts the selection of nodes and the triggering of individual commands meaning that each connection receives its individual
CommandOutput
andCommandArgs
object.async().replicas().commands().dispatch(…)
fails because all connections try to write toNestedMultiOutput
(i.e. they share a single output object) and that is actually a problem because each response requires its own output.I think we need to do something about it, specifically throw an exception that this method cannot be used and we need to document that behavior. Instead, we could introduce a
dispatch
method that takes aSupplier<? extends CommandOutput>
so that eachdisp…