lettuce icon indicating copy to clipboard operation
lettuce copied to clipboard

Mark transactions (multi) for coroutine as deprecated

Open Distractic opened this issue 2 years ago • 6 comments

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

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

Distractic avatar Mar 29 '23 04:03 Distractic

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.

mp911de avatar Mar 29 '23 07:03 mp911de

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.

Distractic avatar Mar 29 '23 08:03 Distractic

while waiting for a possible fix.

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

mp911de avatar Mar 29 '23 08:03 mp911de

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

mgroth0 avatar May 11 '23 21:05 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?

mgroth0 avatar May 11 '23 21:05 mgroth0

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

mp911de avatar May 12 '23 06:05 mp911de