English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Exec Command

Redis Transactions

The Redis Exec command is used to execute all commands within a transaction block.

Syntax

Basic Syntax of Redis Exec Command

redis 127.0.0.1:6379Exec

Available Version

>= 1.2.0

Return Values

The return values of all commands within the transaction block are arranged in the order of command execution. When the operation is interrupted, return an empty value nil.

Online Examples

# The transaction was successfully executed
redis 127.0.0.1:6379MULTI
OK
redis 127.0.0.1:6379INCR user_id
QUEUED
redis 127.0.0.1:6379INCR user_id
QUEUED
redis 127.0.0.1:6379INCR user_id
QUEUED
redis 127.0.0.1:6379PING
QUEUED
redis 127.0.0.1:6379EXEC
1) (integer) 1
2) (integer) 2
3) (integer) 3
4) PONG
# Watch key, and the transaction was successfully executed
redis 127.0.0.1:6379WATCH lock lock_times
OK
redis 127.0.0.1:6379MULTI
OK
redis 127.0.0.1:6379SET lock "huangz"
QUEUED
redis 127.0.0.1:6379INCR lock_times
QUEUED
redis 127.0.0.1:6379EXEC
1) OK
2) (integer) 1
# Watch key, and the transaction was interrupted
redis 127.0.0.1:6379WATCH lock lock_times
OK
redis 127.0.0.1:6379MULTI
OK
redis 127.0.0.1:6379SET lock "joe" # At this moment, another client modified the value of lock_times
QUEUED
redis 127.0.0.1:6379INCR lock_times
QUEUED
redis 127.0.0.1:6379EXEC # Because lock_times was modified, Joe's transaction execution failed
(nil)

Redis Transactions