Exec"."/> Exec".">

Home >Database >Redis >What is the usage of exec of redis in php

What is the usage of exec of redis in php

WBOY
WBOYOriginal
2022-02-23 15:57:362589browse

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".

What is the usage of exec of redis in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What is the usage of redis' exec in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn