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.

ERR MULTI calls can not be nested

See original GitHub issue

my code: public static void main(String[] args) throws Exception { final RedisConnection<String, byte[]> sync = new RedisClient(“10.58.52.60”, 5021) .connect(new BytesCodec()); sync.flushall();

     final CountDownLatch c = new CountDownLatch(1);
        new Thread(new Runnable() {
            public void run() {
                try {
                    c.await();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                sync.multi();
                sync.set("a", Thread.currentThread().getName().getBytes());
                sync.set("a1", Thread.currentThread().getName().getBytes());
                System.out.println(1234);
            }
        }).start();
        new Thread(new Runnable() {
            public void run() {
                try {
                    c.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                sync.multi();
                sync.set("a", Thread.currentThread().getName().getBytes());
                sync.set("a1", Thread.currentThread().getName().getBytes());
                sync.exec();
                System.out.println(5678);
            }
        }).start();

        c.countDown();


}

output: Exception in thread “Thread-2” com.lambdaworks.redis.RedisCommandExecutionException: ERR MULTI calls can not be nested at com.lambdaworks.redis.LettuceFutures.await(LettuceFutures.java:76) at com.lambdaworks.redis.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:59) at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87) at $Proxy5.multi(Unknown Source) at com.lambdaworks.redis.AsyncConnectionConcurrentTest$2.run(AsyncConnectionConcurrentTest.java:44) at java.lang.Thread.run(Thread.java:662) 1234

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, May 29, 2015

Thank you for your report. lettuce connections are in general threadsafe but not stateless. Issuing a MULTI command will turn lettuce connections into a transactional state. All commands issued after a MULTI command are then within the transaction scope until either EXEC or DISCARD are issued.

The connection state means also, that calling MULTI twice will initiate the transaction twice and then try again to start the transaction. The mentioned exception ERR MULTI calls can not be nested is issued by Redis. I assume, that your test case can change the connection in a state, where the first transaction state might be lost, but I have to check this first.

Can you tell me about your expectation in this case?

0reactions
benjamin-badercommented, Jul 12, 2018

Thanks for the sensible explanation. I see now what you mean by “threadsafe but stateful”. Individual commands are sent in a threadsafe manner, but application logic (transactions) must be synchronized at a higher level.

Read more comments on GitHub >

github_iconTop Results From Across the Web

transactions - In Redis, what happens when there is a MULTI ...
If this module starts another multi, redis server will respond with "(error) ERR MULTI calls can not be nested", but the query buffer...
Read more >
Issue 180 in redis: Nested MULTI command does not raise error
1. Issue MULTI and then any number of std cmds · 2. Issue another MULTI cmd before either EXEC or DISCARD and then...
Read more >
lettuce-io/Lobby - Gitter
I have no experience regarding performance of either solution, so I suggest you benchmark ... I'm getting "ERR MULTI calls can not be...
Read more >
Handling SQL Server Errors in Nested Procedures
But when you nest calls to stored procedures, and the proced. ... If the error is fatal, you cannot catch the error in...
Read more >
Lettuce Reference Guide
Using multiple databases. Result handles. Every command invocation on the asynchronous API creates a RedisFuture<T> that can be canceled ...
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