Transactions in Redis
Redis as a NOSQL data store provides a loose sense of transaction. As in a traditional RDBMS, the transaction starts with a BEGIN
and ends with either COMMIT
or ROLLBACK
. All these RDBMS servers are multithreaded, so when a thread locks a resource, it cannot be manipulated by another thread unless and until the lock is released. Redis by default has MULTI
to start and EXEC
to execute the commands. In case of a transaction, the first command is always MULTI
, and after that all the commands are stored, and when EXEC
command is received, all the stored commands are executed in sequence. So inside the hood, once Redis receives the EXEC
command, all the commands are executed as a single isolated operation. Following are the commands that can be used in Redis for transaction:
MULTI
: This marks the start of a transaction blockEXEC
: This executes all the commands in the pipeline afterMULTI
WATCH
: This watches the keys for conditional execution of a transactionUNWATCH
: This...