In this article you are going to learn about Redis Transactions. It is useful when you either want to perform all the transactions or you want to rollback everything. This feature is almost present in all the databases.
Table of Contents
Below Commands are the basic building blocks of Redis Transactions.

What are the key properties of Transactions?
Transactions guarantee that they are executed in sequence.
Either all commands are processed or none are processed.
127.0.0.1:6379> keys * 1) "ticket_available" 127.0.0.1:6379> multi OK 127.0.0.1:6379> get ticket_available QUEUED 127.0.0.1:6379> decr ticket_available QUEUED 127.0.0.1:6379> exec 1) "3" 2) (integer) 2 127.0.0.1:6379>
If Error Occurs then Transaction is aborted
127.0.0.1:6379> keys *
1) "ticket_available"
127.0.0.1:6379> multi
OK
127.0.0.1:6379> ticket_available
(error) ERR unknown command `ticket_available`, with args beginning with:
127.0.0.1:6379> get ticket_available
QUEUED
127.0.0.1:6379> decr ticket_available
QUEUED
127.0.0.1:6379> exec
(error) EXECABORT Transaction discarded because of previous errors.
127.0.0.1:6379>
Discarding a Transaction
127.0.0.1:6379> multi
OK
127.0.0.1:6379> get ticket_available
QUEUED
127.0.0.1:6379> incr ticket_available
QUEUED
127.0.0.1:6379> discard
OK
127.0.0.1:6379> get ticket_available
"2"
127.0.0.1:6379>
“Watch” Redis Keys during Transaction , Fail if value changes.
127.0.0.1:6379> watch ticket_available
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379> get ticket_available
QUEUED
127.0.0.1:6379> decr ticket_available
QUEUED
127.0.0.1:6379> exec
(nil)
Read more about Redis Here.
- Redis Cluster InstallationRedis Cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. In this article, I am going to share steps of Redis …
- Redis Sets Datatype and CommandsRedis SADD – Creating and Adding Members to Redis Sets. sadd users_ip 10.0.0.1 sadd users_ip 10.0.0.2 10.0.0.3 192.168.0 Redis SCARD – Checking total numbers of members available in a …
- Redis TransactionsIn this article you are going to learn about Redis Transactions. It is useful when you either want to perform all the transactions or you want to rollback everything. …
- Installing Redis on WindowsIn this article I will guide you step by step on Installing Redis on Windows. Do remember that Redis is not an officially supported Operating System. I do not …
- What is the fastest way to insert bulk data to Redis?So, you want to insert bulk data to Redis and is really not having any clue that which is the fastest way to insert bulk data to Redis. Continue …
What is the fastest way to insert bulk data to Redis? Read More »
You may also consider subscribing to my Youtube Channel here.
You must be logged in to post a comment.