Redis - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Redis Transaction

Redis Transaction

shape Description

Redis will supports for transactions and can group multiple Redis commands together to insure that they get executed as single unit, which will not be interrupted and all the the commands will be executed. Another way to say this that Redis transactions are atomic. In Redis transactions are started using the multi command. Any commands entered after this point are cued by Redis until either the exact or Discard commands. There is one really important thing to understand about Redis transactions. And are actually queuing up the commands for the transactions, when the user run the transaction it will actually fail and it won't run any of the commands. The only time that res will actually run commands after an error has occurred is if that error occurs when the transaction is actually executing as opposed to when the commands are being queued up to be executed.

Transaction commands

shape Description

The transaction commands explain the basic functionality of Redis database
S.NO Command Description
1 EXEC Execute all commands issued after multi
2 DISCARD Discard all commands issued after multi
3 MULTI Mark the start of a transaction block
4 UNWATCH Forget about all watched keys
5 WATCH key [key...] Watch the given keys to determine execution of the multi/exec block

Example

shape Description

The following example describes the basic functionality of a transaction in Redis database. [c] redis 127.0.0.1:6379> MULTI OK redis 127.0.0.1:6379> SET preparing redis QUEUED redis 127.0.0.1:6379> GET preparing QUEUED redis 127.0.0.1:6379> INCR visitors QUEUED redis 127.0.0.1:6379> EXEC OK "redis" (integer) 1 [/c]

Summary

shape Key Points

  • Transaction - Supports for multiple groups in Redis commands for insuring the interrupted and executed key values.
  • Transaction commands - Describe the basic functionalities of Redis database.