Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the purpose of the Redis Transactions command

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is the function of the Redis Transactions command". In the daily operation, I believe that many people have doubts about the role of the Redis Transactions command. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the function of the Redis Transactions command?" Next, please follow the editor to study!

The biggest difference between Redis transactions and our common database transactions is that if one of the Redis transactions fails, the other commands can still be executed successfully. The transaction for Redis starts with MULTI and is triggered by EXEC. All operations prior to EXEC will be placed in the cache queue. Commands from other clients are not inserted into the transaction during transaction execution. Let's take a look at Redis transaction-related commands.

DISCARD

Earliest available version: 2.0.0

Discard all commands in the queue and set the connection state to normal. If the transaction is WATCH, cancel all WATCH.

EXEC

Earliest available version: 1.2.0

Execute all commands in the queue and set the connection state to normal. If some key is being monitored and there are commands related to these key in the queue. Then the EXEC command will execute the transaction only if the value of these key does not change, otherwise the transaction will be interrupted.

MULTI

Earliest available version: 1.2.0

Marks the beginning of the transaction block, and subsequent commands are sequentially inserted into the cache queue, which can be executed with the EXEC command.

UNWATCH

Earliest available version: 2.2.0

Time complexity: O (1)

Clear all key that has been WATCH, and if you call the EXEC or DISCARD command, you don't have to call the UNWATCH command manually.

WATCH

Earliest available version: 2.2.0

Time complexity: O (1) for each

Marks the specified key as monitored, and if the transaction is changed before execution, the transaction will be interrupted.

Finally, give me a chestnut whose business was interrupted.

1127.0.0.1 6379 > SET lock_time 1

2OK

3127.0.0.1 purl 6379 > WATCH lock_time

4OK

5127.0.0.1 purl 6379 > MULTI

6OK

7127.0.0.1 6379 > SET transcation_key z # then another client executes the command SET lock_time 2

8QUEUED

9127.0.0.1 purl 6379 > INCR lock_time

10QUEUED

11127.0.0.1 6379 > EXEC

12 (nil)

13127.0.0.1purl 6379 > GET transcation_key

14 (nil)

At this point, the study of "what is the function of the Redis Transactions command" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report