redis-- Affairs

  • grammar
    • MULTI
      • Open affairs, subsequent commands will be added to the same transaction
      • Operations in the transaction will be sent to the server, but it does not happen immediately, but put on a queue corresponding to the transaction, the server returns QUEUED
    • EXEC
      • After performing EXEC, commands in the transaction will be executed
      • Commands in the transaction when an error occurs, the transaction will not be rolled back will not stop, but continue
    • DISCARD
      • Cancel the transaction, the transaction will clear the queue, the client exits state of affairs
  • ACID
    • Atomicity
      • not support
      • It does not roll back and continue
    • Isolation
      • stand by
      • Transaction command execution order, and will not be interrupted (the first EXEC first execution) other clients
      • Stand-alone redis read and write operations using a single-threaded process
    • Endurance
      • It does not support, redis data easily lost
    • consistency
      • not support
      • Strong consistency requirement is achieved by optimistic locking (watch)

WATCH

  • redis achieve optimistic locking
  • mechanism
    • Before the transaction open, listening to the data set, EXEC, if found data has been modified, the transaction is automatically canceled (DISCARD)
    • After the transaction EXEC, regardless of success or failure, the listener will be removed
WATCH mykey  # 监视mykey的值
MULTI  # 开启事务
SET mykey 10  
EXEC  # 如果mykey的值在执行exec之前发生过改变, 则该事务会取消(客户端可以在发生碰撞后不断重试)

setnx and pessimistic locking

  • setnx key does not exist, will be set up successfully

  • Non-transactional pipeline

Guess you like

Origin www.cnblogs.com/oklizz/p/11414318.html