Home > database >  REDIS thread-safe access?
REDIS thread-safe access?

Time:09-18

Leave you a question, I have a scene: set a counter in REDIS, client access time, this adds a counter and could you tell me the client if concurrent big, REDIS can ensure the correctness of the result? Similar to a database transaction, will strictly ensure the order of the update data?

CodePudding user response:

Value add a version number of the advice I can give deposit such as timestamp or common value, each time you update the data than the first version

CodePudding user response:

1. Redis is single thread running, so multiple redis command is a an execution, so is thread-safe 2. But separate two redis command, for [used] is not thread-safe, because between the two redis command will have other commands, like Java thread unsafe i++ operation, the two redis commands no transaction management
3. You can use RPOPLPUSH INCR or lua scripts, implement multiple redis operation into a command, thus to [applications] thread safe
  • Related