ERR MULTI calls can not be nested
See original GitHub issuemy 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:
- Created 8 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top GitHub Comments
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 aMULTI
command are then within the transaction scope until eitherEXEC
orDISCARD
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 exceptionERR 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?
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.