1 year ago

#320640

test-img

Lutosław

Lettuce StatefulRedisConnection async command execution order

I'm confused a bit about order of Redis command execution when using a Lettuce driver. Examples use code like

private val cacheConnection: StatefulRedisConnection<String, String>

// (...)

cacheConnection.async().getset(keyStr, json)
cacheConnection.async().expire(keyStr, expireAfterWrite)

https://github.com/lettuce-io/lettuce-core/issues/1627

https://www.baeldung.com/java-redis-lettuce

However, the documentation states

good example is the async API. Every invocation on the async API returns a Future (response handle) after the command is written to the netty pipeline. A write to the pipeline does not mean, the command is written to the underlying transport. Multiple commands can be written without awaiting the response. Invocations to the API (sync, async and starting with 4.0 also reactive API) can be performed by multiple threads.

(https://github.com/lettuce-io/lettuce-core/wiki/Pipelining-and-command-flushing)

This does not specify when the commands are put in the pipeline. Shouldn't I use thenAccept instead?

cacheConnection.async().getset(keyStr, json)
    .thenAccept { expire(keyStr, expireAfterWrite) }

That would mean that all these examples are wrong which is... improbable?

Can you please explain how does it work? Is execution order preservation just a systematic coincidence (ie an implementation detail)?

java

kotlin

redis

lettuce

0 Answers

Your Answer

Accepted video resources