Exec"."/> Exec".">
In Redis, exec is used to execute commands within all transaction blocks. The return values of all commands within the transaction block are arranged in the order of command execution. When the operation is interrupted, a null value is returned." nil", the syntax is "redis > Exec".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
The Redis Exec command is used to execute commands within all transaction blocks.
The basic syntax of the redis Exec command is as follows:
redis 127.0.0.1:6379> Exec
Return value
The return value of all commands in the transaction block, arranged in the order of command execution. When the operation is interrupted, the empty value nil is returned.
Examples are as follows:
# 事务被成功执行 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 # 监视 key ,且事务成功执行 redis 127.0.0.1:6379> WATCH lock lock_times OK redis 127.0.0.1:6379> MULTI OK redis 127.0.0.1:6379> SET lock "huangz" QUEUED redis 127.0.0.1:6379> INCR lock_times QUEUED redis 127.0.0.1:6379> EXEC 1) OK 2) (integer) 1 # 监视 key ,且事务被打断 redis 127.0.0.1:6379> WATCH lock lock_times OK redis 127.0.0.1:6379> MULTI OK redis 127.0.0.1:6379> SET lock "joe" # 就在这时,另一个客户端修改了 lock_times 的值 QUEUED redis 127.0.0.1:6379> INCR lock_times QUEUED redis 127.0.0.1:6379> EXEC # 因为 lock_times 被修改, joe 的事务执行失败 (nil)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of exec of redis in php. For more information, please follow other related articles on the PHP Chinese website!