redis Affairs (optimistic and pessimistic locking lock)

MOUTH

  Open affairs, subsequent commands will be added to the same transaction

  Action sends a transaction to the customer side, but is not performed immediately, but the operation into a queue corresponding to the transaction, the server returns QUEQUD

 

EXEC

  After performing EXEC, the command will execute the transaction

  When the transaction command, it does not roll back will not stop, but continue to the next step

 

DISCARD

  Cancel the transaction, the transaction queue will be cleared

 

Atomicity: does not support, will not be rolled back,

Isolation: support, command sequence affairs, will not be interrupted

Persistence: Does not support

Consistency: Does not support required to achieve through optimistic locking watch

 

Optimistic locking: watch

  redis achieve optimistic locking mechanism

  Mechanism: Before turning on the transaction, set up to monitor data, EXEXC, if data has been modified, the transaction is automatically canceled (DISCARD)

  After the transaction EXEC, regardless of success or failure, the listener will be removed

Sample code:

 

Pessimistic lock:

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/wjun0/p/11884240.html