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.

Redis Transactions 1
Redis Transactions 2

Example

Let's take an example to see how Redis transaction can be initiated and executed.

Example

Redis Transactions 3

Redis Transaction Commands

Following is a list of some basic commands of Redis transaction.

IndexCommandDescription
1DISCARDIt is used to discard all commands issued after MULTI
2EXECIt is used to execute all commands issued after MULTI
3MULTIIt is used to mark the start of a transaction block
4UNWATCHIt is used to forget about all watched keys
5WATCH key [key ...]It is used to watche the given keys to determine the execution of the MULTI/EXEC block

Next TopicRedis Scripting




Latest Courses