introduce

You can execute more than one command at a time, which is essentially a collection of commands. All commands in a transaction are serialized, executed sequentially and not inserted by other commands, without any padding.

The nature of the

The execution of a sequence of commands in a queue at one time, sequentially, and exclusively.

Common commands

The command describe
DISCARD Cancels the transaction, abandoning all commands in the transaction block
EXEC Execute all commands within the transaction block
MULTI Marks the start of a transaction
UNWATCH Unmonitor all keys with the watch command
WATCH key [key] Monitor a key (or keys) and if the key (or keys) is changed by another command before the transaction is executed, the transaction will be interrupted (once exec or discard is executed, previously added monitoring locks will be removed).
## Case study
Summary of redis transaction execution in a variety of situations, summarized in the following five points:
  1. Normal execution

  1. Give up the transaction

3. Keep company with you, you will always be red4. Creditors5. Watch Monitor – Initialize data– No tampering. Enable the monitoring before executing the transaction to ensure that the two values are changed in the same transaction– There is a block condition, the key is monitored and during the period before committing the transaction, if the key is changed, the transaction execution is invalid Note: Once an exec or discard is executed, previously added monitoring locks are removed6. Unwatch Unmonitor

conclusion

  1. Isolated operations: All commands in a transaction are serialized and executed sequentially. Transactions are not interrupted by requests from other clients while they are waiting to execute.
  2. There is no concept of isolation level: commands in queues are not executed until they are committed (exec), just queued in an orderly manner.
  3. No guarantee of atomicity: If a command fails to execute in Redis, subsequent commands will still be executed without rollback.