Setting up your first Redis instance

Before you start tweaking configuration files or tuning settings, let’s get Redis up and running. The simplest way, no matter what operating system you’re using, is with Docker. It takes the guesswork out of setup and gives you a clean, isolated environment every single time.

1. Run Redis with Docker

Open your terminal and run the following command.

docker run -d --name my-redis-server -p 6379:6379 redis/redis-stack-server:latest

Here’s what it means:

  • docker run: The standard command to create and start a new container.
  • -d: Runs the container in "detached" mode, so it runs in the background.
  • --name my-redis-server: Gives your container a friendly, memorable name.
  • -p 6379:6379: Maps port 6379 on your machine to port 6379 inside the container.
  • redis/redis-stack-server:latest: Tells Docker to use the official Redis image.

2. Connect with the Command Line Interface (CLI)

Now that your server is running, let's talk to it. The primary tool for this is redis-cli. You can have Docker run the CLI and connect it to your server with this command:

docker exec -it my-redis-server redis-cli

If it connects successfully, your terminal prompt will change to 127.0.0.1:6379>.

3. Run your first commands

Let’s make sure everything is working as expected.

Let’s make sure everything is working. First, test the connection with PING:

127.0.0.1:6379> PING

PONG

The PONG response means your server is alive. Now, let's try storing and retrieving data:

127.0.0.1:6379> SET status "up and running"

OK

127.0.0.1:6379> GET status

"up and running"

Congratulations, you're now running Redis! With this working instance, we're ready to configure it for the real world.

Security: Lock it down before you do anything else

Redis ships with minimal security enabled, and because it’s so easy to start, security is often forgotten until something goes wrong. Don’t let that be your story, so take these steps first:

  • Network interface binding (bind): Make sure Redis only listens on the IPs you trust, usually localhost and your private network. Never expose it directly to the public internet.
  • Authentication (requirepass): Always set a strong password so only trusted clients can connect.
  • Protected mode (protected-mode): Keep this on. It’s an extra layer of safety, making sure Redis only accepts connections from addresses you’ve set.
  • Disable risky commands (rename-command): In production, commands like FLUSHALL or CONFIG can be dangerous. You can disable them by renaming to an empty string.

# Bind to localhost and a trusted private network IP

bind 127.0.0.1 192.168.10.5

# Enable authentication with a strong password

requirepass "Rz$v!8N#pTq*2k@wF&sC"

# Leave this enabled as a critical safety feature

protected-mode yes

# Disable FLUSHALL to prevent accidental data wipes

rename-command FLUSHALL ""

Don’t lose data: Configure persistence

By default, Redis is volatile, so if it restarts, your data disappears. If you can’t afford that risk, persistence is a must. The most common approach is to enable both AOF and RDB:

  • AOF (Append-Only File): This is your best bet for durability. Every change gets logged, so you only risk losing up to one second of data with the default setting.
  • RDB (Snapshotting): Creates point-in-time snapshots for backup. It’s lighter on resources, but you could lose more data between snapshots.

Production best practice: Enable both AOF and RDB. When both are active, Redis uses the more durable AOF for recovery, while the RDB file remains available for faster replica seeding and backups.

# Enable AOF for maximum durability

appendonly yes

Plan for high availability: Avoid single points of failure

A single Redis server is a single point of failure. Production setups use replication, so your main server (Leader) is always being copied to one or more Followers. This way, if the Leader fails, your data isn’t lost.

But replication alone isn’t enough. Add Redis Sentinel for automated failover. Sentinel monitors your servers, and if the Leader goes down, it promotes a Follower and updates your cluster so you stay online with minimal disruption.

Get the most out of Redis: Optimize for performance

Once you have stability and security, make sure you’re not slowing yourself down with poor practices. A few tips:

Avoid blocking operations

Never use the KEYS command on a busy server, as it locks up the instance. Use SCAN for safe iteration instead.

Use efficient data structures

Take advantage of Redis Hashes for storing related data. It’s more memory-efficient than lots of separate keys.

Optimize client connections

Use pipelining to batch commands, and connection pooling to cut down on overhead.

Monitor performance

Enable SLOWLOG to catch slow operations early. This helps you spot bottlenecks before they impact your users.

From a stable setup to a real advantage

With these basics in place, your Redis deployment will be secure, resilient, and ready for anything. But as your data grows and your needs get more complex, new challenges appear: scaling for more users, planning zero-downtime upgrades, or managing multi-terabyte datasets.

When you reach that point, having experienced support can make the difference between smooth operations and costly downtime.

For all the Redis challenges you didn’t plan for

This guide sets you up for success, but real-world issues in large-scale environments often need expert attention. Whether you’re optimizing multi-terabyte datasets, planning a high-availability cluster, or handling tricky upgrades, it helps to have a partner with deep experience.

Percona’s experts are here for you, offering 24/7 support and consulting for Redis. We help you design, tune, and future-proof your infrastructure so you can focus on what matters most: getting the most from your data.

Get expert Redis help now