Skip to content

Mark transactions (multi) for coroutine as deprecated #2371

Closed

Description

@Distractic

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)}") // executed

The 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 executed
Stack trace
Nothing thrown.

Input Code

Repository

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

Activity

  1. mp911de commented on Mar 29, 2023

    @mp911de
    Collaborator

    Looks like a duplicate of #1954.

    We deprecated the multi extension because of that reason as Redis' transaction do not work well with an async API.

  2. Distractic commented on Mar 29, 2023

    @Distractic
    Author

    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.

  3. mp911de commented on Mar 29, 2023

    @mp911de
    Collaborator

    while waiting for a possible fix.

    No fix is possible as transactional commands only complete after running EXEC.

  4. mgroth0 commented on May 11, 2023

    @mgroth0

    @mp911de, io.lettuce.core.api.coroutines.RedisCoroutinesCommands.multi is not marked as deprecated in 6.2.4.RELEASE

  5. mgroth0 commented on May 11, 2023

    @mgroth0

    Ah I see it is marked as deprecated in the javadoc. But it doesn't have the @Deprecated annotation, so it doesn't produce any warnings. Can a @Depreacted annotation be added to prevent users from accidentally using this?

  6. mp911de commented on May 12, 2023

    @mp911de
    Collaborator

    Yes, sorry for the inconvenience. Let me reopen the ticket so we add proper deprecation annotations.

  7. added and removed on May 12, 2023
  8. added this to the Backlog milestone on Jul 17, 2024
  9. changed the title [-]Transaction (multi) for coroutine doesn't work[/-] [+]Mark transactions (multi) for coroutine as deprecated[/+] on Jul 17, 2024
  10. young0264 commented on Jun 3, 2026

    @young0264
    Contributor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: good-first-issueAn issue that can only be worked on by brand new contributorstype: taskA general task

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址