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 are the commands for things in redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Redis what things command, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Example of the command:

1. The transaction is executed normally:

# client tools that execute Redis under the Shell command line.

/ > redis-cli

# start a new transaction on the current connection.

Redis 127.0.0.1 6379 > multi

OK

# execute the first command in the transaction. From the return result of the command, you can see that the command is not executed immediately, but is stored in the command queue of the transaction.

Redis 127.0.0.1 6379 > incr T1

QUEUED

# execute a new command, which can be seen from the result that it is also stored in the command queue of the transaction.

Redis 127.0.0.1 6379 > incr T2

QUEUED

# execute all the commands in the transaction command queue, and you can see from the results that the results of the commands in the queue are returned.

Redis 127.0.0.1 6379 > exec

1) (integer) 1

2) (integer) 1

two。 There are failed commands in the transaction:

# start a new transaction.

Redis 127.0.0.1 6379 > multi

OK

# set the value of key a to 3 of type string.

Redis 127.0.0.1 6379 > set a 3

QUEUED

# pops the element from the header of the value associated with key a. Because the value is of type string and the lpop command can only be used for type List, the command will fail when executing the exec command.

Redis 127.0.0.1 6379 > lpop a

QUEUED

# set the value of key a to string 4 again.

Redis 127.0.0.1 6379 > set a 4

QUEUED

# gets the value of key a to confirm whether the value was set successfully by the second set command in the transaction.

Redis 127.0.0.1 6379 > get a

QUEUED

# as can be seen from the results, the second command in the transaction, lpop, failed, while the subsequent set and get commands were executed successfully, which is the most important difference between transactions in Redis and transactions in relational databases.

Redis 127.0.0.1 6379 > exec

1) OK

2) (error) ERR Operation against a key holding the wrong kind of value

3) OK

4) "4"

3. Roll back the transaction:

# set a pre-transaction value for key T2.

Redis 127.0.0.1 tt 6379 > set T2 tt

OK

# start a transaction.

Redis 127.0.0.1 6379 > multi

OK

# set a new value for the key within the transaction.

Redis 127.0.0.1 ttnew 6379 > set T2 ttnew

QUEUED

# abandon the transaction.

Redis 127.0.0.1 6379 > discard

OK

# looking at the value of the key T2, you can see from the result that the value of the key is still the value before the start of the transaction.

Redis 127.0.0.1 6379 > get T2

"tt"

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Servers

Wechat

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

12
Report