Giter Club home page Giter Club logo

Comments (8)

mp911de avatar mp911de commented on May 27, 2024 1

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.

mp911de avatar mp911de commented on May 27, 2024 1

Until now, no further action, but it might be worth having a sketch for a transactional buffer utility.

from lettuce.

carlvine500 avatar carlvine500 commented on May 27, 2024

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.

mp911de avatar mp911de commented on May 27, 2024

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.

carlvine500 avatar carlvine500 commented on May 27, 2024

thanks , I will try it .

from lettuce.

benjamin-bader avatar benjamin-bader commented on May 27, 2024

@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.

mp911de avatar mp911de commented on May 27, 2024

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.

benjamin-bader avatar benjamin-bader commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.