0
0
Redisquery~5 mins

MULTI command to start in Redis

Choose your learning style9 modes available
Introduction

The MULTI command in Redis is used to start a group of commands that will run together as a single unit. This helps keep your data changes safe and organized.

When you want to make several changes to your data all at once without interruptions.
When you need to ensure that a set of commands either all happen or none happen.
When you want to avoid other commands running between your important changes.
When you want to prepare a batch of commands to send to Redis and execute them later.
When you want to keep your data consistent during multiple related updates.
Syntax
Redis
MULTI

This command starts a transaction block in Redis.

After MULTI, you send commands that will be queued and run together when you call EXEC.

Examples
This example starts a transaction, sets two keys, and then runs all commands together.
Redis
MULTI
SET key1 "value1"
SET key2 "value2"
EXEC
This example increments a counter twice inside a transaction.
Redis
MULTI
INCR counter
INCR counter
EXEC
Sample Program

This transaction sets the name and age for user 1 together.

Redis
MULTI
SET user:1:name "Alice"
SET user:1:age "30"
EXEC
OutputSuccess
Important Notes

Commands after MULTI are queued and not executed immediately.

Use EXEC to run all queued commands at once.

If you want to cancel the transaction, use DISCARD instead of EXEC.

Summary

MULTI starts a transaction block in Redis.

Commands inside MULTI are queued and run together with EXEC.

This helps keep your data changes safe and consistent.