Closed
Labels
status: good-first-issueAn issue that can only be worked on by brand new contributorsAn issue that can only be worked on by brand new contributorstype: taskA general taskA general task
Milestone
Description
Bug Report
Current Behavior
Based on this connection pool : BoundedAsyncPool<StatefulRedisConnection<ByteArray, ByteArray>>
If we got a connection, use sync() method and multi to make transaction, the transaction is performed as expected
val pool: BoundedAsyncPool<StatefulRedisConnection<ByteArray, ByteArray>> = ...
val connection: StatefulRedisConnection<ByteArray, ByteArray> = pool.acquire().await()
val result = connection.sync().multi {
get(key1)
get(key2)
sismember(key3, "test".encodeToByteArray())
}
println("Executed multi: $result ") // executed
println("Result 0: ${result.get<ByteArray>(0)}") // executedThe prints display information as expected and the transaction is executed.
However, if we're using the coroutine, the transaction will just block and never be performed
val pool: BoundedAsyncPool<StatefulRedisConnection<ByteArray, ByteArray>> = ...
val connection: RedisCoroutinesCommands<ByteArray, ByteArray> = pool.acquire().await().coroutines()
val result = connection.multi {
get(key1)
get(key2)
sismember(key3, "test".encodeToByteArray())
}
println("Executed multi: $result ") // never executed
println("Result 0: ${result.get<ByteArray>(0)}") // never executedStack trace
Nothing thrown.Input Code
Details
Expected behavior/code
The transaction should be executed using coroutine extension
Environment
- Lettuce version(s): [6.2.3.RELEASE]
- Redis version: [7.0.8]
- Kotlin: [1.8.0]
- Coroutine: [1.6.4]
Possible Solution
Additional context
Metadata
Metadata
Assignees
Labels
status: good-first-issueAn issue that can only be worked on by brand new contributorsAn issue that can only be worked on by brand new contributorstype: taskA general taskA general task
Activity
mp911de commentedon Mar 29, 2023
Looks like a duplicate of #1954.
We deprecated the
multiextension because of that reason as Redis' transaction do not work well with an async API.Distractic commentedon Mar 29, 2023
Ok thanks ! And sorry for the duplicate
So for the moment, we can't use transaction. I will just make several requests in this case while waiting for a possible fix.
mp911de commentedon Mar 29, 2023
No fix is possible as transactional commands only complete after running
EXEC.mgroth0 commentedon May 11, 2023
@mp911de,
io.lettuce.core.api.coroutines.RedisCoroutinesCommands.multiis not marked as deprecated in 6.2.4.RELEASEmgroth0 commentedon May 11, 2023
Ah I see it is marked as deprecated in the javadoc. But it doesn't have the
@Deprecatedannotation, so it doesn't produce any warnings. Can a@Depreactedannotation be added to prevent users from accidentally using this?mp911de commentedon May 12, 2023
Yes, sorry for the inconvenience. Let me reopen the ticket so we add proper deprecation annotations.
[-]Transaction (multi) for coroutine doesn't work[/-][+]Mark transactions (multi) for coroutine as deprecated[/+]young0264 commentedon Jun 3, 2026
Hi @mp911de,
I checked the current coroutine transaction API.
It looks like the DSL-style RedisCoroutinesCommands.multi { ... } extension is already documented as deprecated since 6.1.6, but it is missing a Kotlin @deprecated annotation, so users do not get compiler or IDE warnings.
The issue seems to come from the mismatch between Redis transaction semantics and the coroutine suspend command model: commands issued after MULTI are queued and their actual results are only available after EXEC, while the DSL makes it easy for users to write code that awaits those command results inside the transaction block.
I opened a small PR that adds the missing @deprecated annotation to that extension only, without changing runtime behavior.
For the deprecation message, I used a shorter message to keep it closer to the existing Lettuce style:
@deprecated("since 6.1.6, coroutine transaction DSL commands complete only after EXEC")
Thank you.
Add deprecation annotation to coroutine multi DSL redis#2371
Add deprecation annotation to coroutine multi DSL redis#2371
Add deprecation annotation to coroutine multi DSL redis#2371
Add deprecation annotation to coroutine multi DSL #2371 (#3771)