Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

A brief introduction to Redis transactions

Shulou Source: shulou.com Published: 2022-06-02 04:39:03 10月02日 Update

This article introduces the relevant knowledge of "A brief introduction to Redis affairs". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Transactions represent a set of actions, either all or none. Redis provides a simple transaction function, placing a set of commands that need to be executed together between multi and exec commands, multi commands represent the beginning of the transaction, and exec commands represent the end of the transaction. The orders between them are carried out by atoms.

Multi/exec127.0.0.1:6379 > multiOK127.0.0.1:6379 > set key1 v1QUEUED127.0.0.1:6379 > set key2 v2QUEUED127.0.0.1:6379 > exec1) OK2) OKdisacard

If you stop the execution of the transaction, you can use the disacard command instead of exec fame and fortune.

127.0.0.1 discardOK127.0.0.1:6379 6379 > multiOK127.0.0.1:6379 > set key1 vv1QUEUED127.0.0.1:6379 > discardOK127.0.0.1:6379 > get key1 "v1" watch

Make sure that the key in the transaction has not been modified by other clients before executing the transaction or not, similar to optimistic locking.

This is the end of the brief introduction to Redis transactions. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Transactions commands between representatives content more knowledge or practical optimistic successful learning and then two functions actions atoms fame and wealth dilemmas practice customers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Shulou Information Apple MariaDB