Comments (8)
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?
from lettuce.
Until now, no further action, but it might be worth having a sketch for a transactional buffer utility.
from lettuce.
diffrent business data stored in redis with diffrent dbIndex ,
I will concurrently send command ( multi ; select x; set y ; exec;)
then I get this error.
from lettuce.
You will need two connections, every connection can be at one database at a time. All commands are issued immediately to Redis, even those preceded by a MULTI
commands. This means commands are not buffered until you fire EXEC
.
from lettuce.
thanks , I will try it .
from lettuce.
@mp911de Apologies for resurrecting such an old thread, but I'm having a little conceptual trouble with this. I just hit this error, and don't quite understand something you said upthread:
lettuce connections are in general threadsafe but not stateless
What does this mean? Generally, statefulness implies non-threadsafe. Is it the case that a MULTI call requires thread synchronization? That is, if we use MULTI, must we guarantee that only that thread is actively using the connection?
from lettuce.
Statefulness and thread-safety are not mutually exclusive. Lettuce connections are initialized and handed over to the application. The initial state is (looking at transactions), that the connection is not in a transactional state. This state can be changed concurrently but requires external synchronization. Without synchronization, things like interleaving or other race conditions may happen.
That is, if we use MULTI, must we guarantee that only that thread is actively using the connection?
In short: Yes, only a single thread is allowed to actively use the connection.
The longer version is:
Without changing the state, a single connection is thread-safe and can be shared across multiple threads. If you need to change the state (run transactions), then you need to introduce some sort of isolation. That can be synchronization (thread 1 runs its transaction and awaits its completion, then thread 2 runs its transaction and so on) or allocating connections per thread (invocation) by e.g. using connection pooling.
from lettuce.
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.
from lettuce.
Related Issues (20)
- Support publishing of long-lived JFR events to the `EventBus`
- Redis health check failed ConcurrentModificationException: null HOT 1
- Make WithLatency visable for better custmization HOT 2
- Tracing is enabled even when using DefaultClientResources
- Add option to customize expected exceptions in `DefaultEndpoint` HOT 1
- nested exception is java.lang.UnsupportedOperationException: io.lettuce.core.output.ValueOutput does not support set(long) HOT 3
- georaduis command execute error when use ReadFrom.REPLICA_PREFERRED HOT 9
- Hash Field Expiration Support HOT 1
- SSL FULL verify seed connection, but only CA verify for cluster node connections
- Getting the keys from cache returns the wrong amount in cluster mode with replica enabled. HOT 1
- Is client side caching enabled by default in lettuce? If yes, Is there a way to not do client side caching in lettuce? HOT 1
- Seeing Warning Logs :: Cannot refresh Redis Cluster topology in 6.2.6.RELEASE HOT 1
- After turning on topology refresh, lettuce log is written inside rocketmq-client.log. HOT 4
- Lettuce client reconnecting frequently HOT 1
- Custom command with Lettuce occurs UnsupportedOperationException HOT 1
- Stateful redis cluster pubsub is not working HOT 1
- Why does lecttuce send lua script load command to all nodes (including replicas) in redis cluster? HOT 4
- `DefaultClientResources.dnsResolver(DnsResolver resolver)` should be marked as deprecated.
- ClusterTopologyChangedEvent Timing Issue
- Provide a convenience method to support reading of last message from stream
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lettuce.