Latest web development tutorials

Redis Multi command

Redis transaction

Redis Multi command is used to mark the beginning of a transaction block.

Multiple commands within a transaction block will be placed in a queue in the order they were last atomic (atomic) executed by the EXEC command.

grammar

redis Multi basic command syntax is as follows:

redis 127.0.0.1:6379> Multi

Available versions

> = 1.2.0

return value

Always returns OK.

Examples

redis 127.0.0.1:6379> MULTI            # 标记事务开始
OK

redis 127.0.0.1:6379> INCR user_id     # 多条命令按顺序入队
QUEUED

redis 127.0.0.1:6379> INCR user_id
QUEUED

redis 127.0.0.1:6379> INCR user_id
QUEUED

redis 127.0.0.1:6379> PING
QUEUED

redis 127.0.0.1:6379> EXEC             # 执行
1) (integer) 1
2) (integer) 2
3) (integer) 3
4) PONG

Redis transaction