It has been several months since reids was studied and used. I have summarized a lot of documents and related materials. In the next time, I will share some relevant materials, this article also describes how to use it in our applications.
The following is an introduction to redis (refer to redis. io ):
I. Use of things
1. Redis transactions start with the MULTI command. This command always returns OK.
2. the user can then execute multiple commands. redis will not immediately execute these commands, but will only put them into the queue.
3. When the exec command is executed, all the commands are executed.
4. Calling the discard command will flush the transaction queue and exit the transaction.
As follows:
Redis 127.0.0.1: 6379> multi
OK
Redis 127.0.0.1: 6379> set foo 1
QUEUED
Redis 127.0.0.1: 6379> incr foo
QUEUED
Redis 127.0.0.1: 6379> incr foo
QUEUED
Redis 127.0.0.1: 6379> exec
1) OK
2) (integer) 2
3) (integer) 3
From the above session, we can see that the reply returned by the multi command is an array. Each element is the reply of every instruction in the transaction, and it is in the same order as the command release. When redis is connected to a multi request, all command responses are queued unless the statement of this command is incorrect. Some commands have correct syntax, but errors in the execution phase are also allowed.
See the following
Redis 127.0.0.1: 6379> multi
OK
Redis 127.0.0.1: 6379> set t 13
QUEUED
Redis 127.0.0.1: 6379> lpop t
QUEUED
Redis 127.0.0.1: 6379> exec
1) OK
2) (error) ERR Operation against a keyholding the wrong kind of value
For this type of err, the client must give a reasonable prompt.
Note that all commands in the queue will be executed, and redis will not terminate the command execution.
Ii. Cancel queue commands
Discard is used to cancel the command queue. A thing can be broken. No commands will be executed, and the connection status is normal.
For example:
> SET foo 1
OK
> MULTI
OK
> INCR foo
QUEUED
> DISCARD
OK
> GET foo
"1"