74
Redis Transactions
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.
Sample
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.
Example
Let’s take an example to see how Redis transaction can be initiated and executed.
Example
Redis Transaction Commands
Following is a list of some basic commands of Redis transaction.
Index | Command | Description |
---|---|---|
1 | DISCARD | It is used to discard all commands issued after MULTI |
2 | EXEC | It is used to execute all commands issued after MULTI |
3 | MULTI | It is used to mark the start of a transaction block |
4 | UNWATCH | It is used to forget about all watched keys |
5 | WATCH key [key …] | It is used to watche the given keys to determine the execution of the MULTI/EXEC block |
Next TopicRedis Scripting