You get a bonus - 1 coin for daily activity. Now you have 1 coin

Transactions in Redis

Lecture



Redis also supports transactions, which allow a group of commands to be
executed in a single step, and other requests' commands cannot
interject into it; at the same time, it guarantees the consistency and
sequential execution of the set of commands, and in case of any problems
it also allows these changes to be rolled back

The following main commands are used to implement transactions in Redis:

MULTI – start recording commands for a transaction.
EXEC – execute the recorded commands.
DISCARD – delete all recorded commands.

WATCH – a command that guarantees a «check-and-set»
(CAS) behavior - the transaction is executed only if
other clients have not modified the value of the variable. Otherwise EXEC will not execute the recorded commands

127.0.0.1:6379> multi

set count 20

127.0.0.1:6379> incr count
QUEUED
127.0.0.1:6379> incr count

> decr count

(integer) 21
(integer) 22
(integer) 21
127.0.0.1:6379>

Now let's try to start a transaction and then abort it.

6379> multi
6379> set foo 0
:6379> incr foo

:6379> discard

127.0.0.1:6379> _

created: 2026-07-12
updated: 2026-07-12
1



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - Redis DB Nosql"

Terms: Databases - Redis DB Nosql