w3resource

Redis Transactions: EXEC

Redis EXEC Command

Redis EXEC command is used to execute all previously queued commands in a transaction and restores the connection state to normal.

Here are some common uses and scenarios for the "EXEC" command:

  • Commit Transaction: Executes all commands queued in a transaction started with the MULTI command, applying changes atomically.
  • Atomic Operations: Ensures that a series of commands are executed as a single, atomic operation, either all succeeding or all failing.
  • Batch Processing: Facilitates batch processing by allowing multiple commands to be processed together, reducing round-trip time.
  • Consistency: Maintains data consistency by applying all commands in the transaction as a unit, ensuring no partial updates.

Syntax:

EXEC

Available since

1.2.0.

Return Value

Array reply, each element being the reply to each of the commands in the atomic transaction.

Return Value Type

Array

Example:

127.0.0.1:6379> MULTI
OK
127.0.0.1:6379> INCR test
QUEUED
127.0.0.1:6379> INCR test1
QUEUED
127.0.0.1:6379> EXEC
1) (integer) 3
2) (integer) 3

Previous: DISCARD
Next: MULTI



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-exec.php