Get started with Redis series (9): Redis transactions and operations (code graphic examples)

Before learning Redis, I still think I must tell you. It is also a sentence that I said a lot in my article. I think it will also apply to learning Redis, that is, when you contact the Reids command in the article, you don’t have to try Remember these commands , just read the API help documentation when you use them; it won’t be too late to understand them after you know how to use them or practice them .

Get started with Redis series

To get started with Redis, you must know: the most basic knowledge points and the most basic common operations

Get started with Redis series (1): Detailed explanation of ultra-full String string type
Get started with Redis series (2): Detailed explanation of ultra-full List list type (code graphic example)
Get started with Redis series (3): Detailed description of ultra-full set Set type (code graphic and text Example)
Getting started with Redis series (4): Detailed explanation of ultra-full hash Hash type (code graphic example)
Getting started with Redis series (5): Detailed explanation of ultra-all ordered collection Zset type Getting
started with Redis series (6): Detailed explanation of ultra-full Geospatial special type (Geographical location)
Get started with Redis series (7): Ultra-full HyperLogLog special types
get started with Redis series (8): Bitmaps special types
get started with Redis series (9): Transaction operations

1. Redis transaction

Speaking of redis transactions, it is necessary to understand the transaction itself.

(If you still have a small partner who understands the affairs, you can understand first)

The interview must know and know: What is a transaction, the four characteristics of a transaction (ACID), and common transaction isolation?

But unlike transactions, there are only partial transactions in redis.

Because redis does not guarantee atomicity and does not have the concept of isolation, what does redis have?

  • One time
  • Sequentiality
  • Exclusivity

Redis transactions can execute multiple commands at once, and there are three important guarantees:

2. Hand knock Redis transaction command:

The flow of a transaction:

1. Open the transaction (muti)
2. Order to join the team (specific operations)
3. Execution transaction (exec)

MULTI starts a transaction, then enters the command into the queue to the transaction, and finally executes the EXEC command and executes the transaction.

Start a transaction

Format: MULT

Execute all transaction block commands

Format: EXEC

Insert picture description here
Cancel transaction

Format: DISCARD

It can be seen that once the transaction is cancelled, the operations in the transaction are also cancelled.

Insert picture description here

At last

At the end, for a better reading experience, I put everything I want to say below, hehe.

I am a seed of decisions based on my will, serious share what I wrote blog has been the same creed.
If you can read this blog post, it means that we are still very destined; I hope it can bring you some help, the creation is not easy,
take away the knowledge of my article, your three consecutive leave, like, comment, follow , Is my biggest motivation.

Guess you like

Origin blog.csdn.net/A_hxy/article/details/108554906