Skip to main content

Installing Redis

Let’s set up your environment so you can start experimenting.

Option 1: Installing on Linux/macOS

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

Option 2: Installing on Windows

Windows support

The official Redis project does not support Windows, but you can use one of the below options for development purposes if you have no other choice.

Using Docker:

docker run --name redis-test -p 6379:6379 -d redis

Loggin into Docker Interactively

docker exec -it redis-test /bin/sh

Option 3: Installing Redis on a Docker Container

Command to run docker container with persistent volume.

docker run --name redis-test -p 6379:6379 -v redis-data:/data -d redis redis-server --appendonly yes

To mount a custom Redis config file into the container and enable persistence, you can use this one-liner:

docker run --name redis-test -p 6379:6379 -v /path/to/redis.conf:/usr/local/etc/redis/redis.conf -v redis-data:/data -d redis redis-server /usr/local/etc/redis/redis.conf

Option 4: Using Redis Cloud

If you don't want to install Redis locally, use a free Redis instance in the cloud:


Checking and managing status of Redis

  • Checking current status of Redis service
sudo systemctl status redis-server
  • Stopping Redis Service
sudo systemctl stop redis-server
  • Starting Redis Service
sudo systemctl start redis-server

Checking Redis Server's configuration file

cat /etc/redis/redis.conf

Connecting to Redis using redis-cli

redis-cli

You should see a prompt like

127.0.0.1>

You can also stop Redis gracefully from CLI with:

127.0.0.1> SHUTDOWN

Your First Redis Commands

Let's try some basic commands using the Redis CLI:

127.0.0.1:6379> SET name "Redis"
OK
127.0.0.1:6379> GET name
"Redis"
127.0.0.1:6379> DEL name
(integer) 1
127.0.0.1:6379> GET name
(nil)

Using Redis from Python

Install the redis-py client:

pip install redis

Sample Python code:

import redis

# Connect to Redis (default localhost:6379)
r = redis.Redis(host='localhost', port=6379, db=0)

# Set a key
r.set('name', 'Redis')

# Get the key
print(r.get('name')) # Output: b'Redis'

# Delete the key
r.delete('name')

Common Troubleshooting for Beginners

  • Not running the Redis server: The CLI and clients need the server running.
  • Port conflicts: The default port is 6379; ensure no other service is using it.
  • Data loss on restart: By default, Redis stores data in memory—unless persistence is enabled, you may lose data between restarts.
  • Firewall/network issues: Ensure your firewall allows connections to Redis if using remote clients.

Recap

In this lesson, you learned:

  • What Redis is and why it’s popular.
  • Common use cases for Redis.
  • How to install and start Redis on your machine or in the cloud.
  • How to run basic commands via the CLI and Python.
  • Common setup mistakes to avoid.

You’re now ready to start exploring Redis in depth!


Quiz

Redis Installation Basics

What is the default port Redis runs on?

Question 1/5

You’re all set! In the next lesson, we’ll dive into Redis core concepts and data structures.