Redis transaction is used to facilitates users to execute group of commands in a single step.
There are two properties of execution:
- All commands in a transaction are sequentially executed as a single isolated operation. You can't issue a request by another client served in the middle of the execution of a Redis transaction.
- Redis transaction is also atomic. Atomic means either all of the commands or none are processed.
In Redis, transaction is initiated by using "MULTI" command and then you need to pass a list of commands that should be executed in the transaction, after which the entire transaction is executed by "EXEC" command.
Let's take an example to see how Redis transaction can be initiated and executed.
Redis Transaction Commands
Following is a list of some basic commands of Redis transaction.
||It is used to discard all commands issued after MULTI
|| It is used to execute all commands issued after MULTI
|| It is used to mark the start of a transaction block
|| It is used to forget about all watched keys
||WATCH key [key ...]
|| It is used to watche the given keys to determine the execution of the MULTI/EXEC block