question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RedisClusterClient use transactions with multi and exec and discard not work

See original GitHub issue

hi I get a RedisClusterAsyncConnection with RedisClusterClient.connectClusterAsync() method. but the transactions not work. code is below.

List<RedisURI> initialUris = new ArrayList<RedisURI>();
initialUris.add(RedisURI.Builder.redis("192.168.2.120", 7000).build());
initialUris.add(RedisURI.Builder.redis("192.168.2.120", 7001).build());
initialUris.add(RedisURI.Builder.redis("192.168.2.120", 7002).build());
initialUris.add(RedisURI.Builder.redis("192.168.2.120", 7004).build());
RedisClusterClient rcc = new RedisClusterClient(initialUris);
RedisClusterAsyncConnection<String, String> conn = rcc.connectClusterAsync();
try {
    if( conn.multi().get().equals("OK") ){
        conn.set("city.name", "beijing");
        System.out.println( 1 / 0);
        conn.exec().get();
    }
} catch (Exception e) {
    conn.discard().get()
}

the code will occur exception, conn.exec().get() not run, conn.discard().get() is run. but the transaction commited. why? please help me!1

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mp911decommented, Jun 30, 2017

There’s no multi support from a top-level cluster connection perspective because there are no distributed transactions in Redis. If you want to use transactions, then obtain a node-specific connection to the node that holds the keys you want to touch within the transaction (StatefulRedisClusterConnection .getConnection(…)).

Please use StackOverflow or the mailing list if you have further questions.

1reaction
yiukaluncommented, Jun 30, 2017

The getConnection API was deprecated in Lettuce 4.

I am not sure how to perform multi() on clustered connection using Lettuce too.

Anyone can help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

RedisClusterClient (Lettuce 6.2.2.RELEASE API)
You should not use transactional commands on cluster connections since MULTI , EXEC and DISCARD have no key and cannot be assigned to...
Read more >
Spring Data Redis - watch and multi on same cluster node
My objective is to apply transaction logic (watch+multi) to a ... repo that transactions on clusters are not supported on spring data redis....
Read more >
Module eredis_cluster - HexDocs
The eredis_cluster application is a Redis Cluster client. ... Function to execute a pipeline of commands as a transaction command, by wrapping it...
Read more >
Introduction to Lettuce - the Java Redis Client - Baeldung
The call to multi starts the transaction. When a transaction is started, the subsequent commands are not executed until exec() is called. In ......
Read more >
Transactions | Redis
How transactions work in Redis. ... of a group of commands in a single step, they are centered around the commands MULTI ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found