Start Redis Server & Client
Step 4 in the Redis track: learn how to start the Redis server and connect with the Redis CLI. Hands-on exercise, troubleshooting, and next steps included.
Focus: start redis server and client
You've installed Redis, but now comes the moment of truth: how do you actually start the server and then talk to it? Without a running server, every Redis command you know is just theory. This lesson cuts through the confusion, showing you exactly how to bring Redis to life and connect with its command-line interface — the moment when your local database stops being an installation and starts being a tool you can use.
The problem this lesson solves
New Redis users often hit a wall right after installation. They type redis-cli and see Could not connect to Redis at 127.0.0.1:6379: Connection refused. Or they run redis-server and it seems to hang forever. The core issue: Redis is a client-server system. The server (redis-server) must be running before any client (redis-cli or your Python app) can interact with it. Without understanding how to start, verify, and stop the server, you can't move forward with any practical Redis work.
Core concept / mental model
Think of Redis like a post office.
redis-serveris the post office building — it needs to be open for business before anyone can send or receive mail.redis-cliis a customer walking up to the counter to drop off a letter or ask for a package. If the post office is closed, the customer leaves disappointed.- Data (your keys, values, lists) are the letters and packages sorted inside the post office.
You can't send mail to a closed post office. In Redis terms, you can't SET a key or GET a value if redis-server isn't listening. The server listens by default on TCP port 6379 on your local machine (localhost). The client connects to that port.
Key definitions
- Redis Server (
redis-server): The daemon/process that manages data in memory, handles commands, and persists to disk. It binds to a port and waits for connections. - Redis Client (
redis-cli): A command-line tool that connects to a running Redis server, sends commands, and displays responses. It's the simplest way to interact with Redis interactively or via scripts. - Connection refused: The most common error, meaning the client reached the network address but no server process was listening on that port.
How it works step by step
Starting Redis isn't magic — it's a deliberate sequence of starting a process and connecting to it. Here's the workflow:
- Launch the server by running
redis-serverin a terminal. You can run it in the foreground (it prints logs and waits) or as a background daemon. - Verify the server is listening by checking its output for the classic Redis logo and a message like
Ready to accept connections tcp. You can also useps aux | grep redis-serveron Linux/Mac or Task Manager on Windows. - Open a new terminal window (or use the same with background process) and run
redis-cli. This command tries to connect to127.0.0.1:6379by default. - Test connectivity with the
PINGcommand. If the server repliesPONG, you have a live connection. Any other response or timeout means something is wrong. - Shut down gracefully using
redis-cli shutdown(saves data to disk) orCtrl+Cin the server terminal.
Daemon mode vs foreground
By default, redis-server runs in the foreground, showing logs. To run it as a background service, use the --daemonize yes flag or set daemonize yes in redis.conf. In a production environment, you'd typically use systemd or your OS's init system.
Hands-on walkthrough
Let's walk through starting the server and client, then running a few commands. Make sure Redis is installed before proceeding (check with redis-cli --version).
Example 1: Start server in foreground (development)
Open your terminal and run:
redis-server
You'll see the Redis ASCII art logo and log output ending with something like:
... Redis 7.2.0 (00000000/0) 64 bit
... Running in standalone mode
... Server initialized
... Ready to accept connections tcp
The terminal now appears blocked — that's the server process running. Keep this terminal open. Open a second terminal.
Example 2: Connect with redis-cli and run commands
In the second terminal:
redis-cli
If successful, you'll see a prompt like 127.0.0.1:6379>. Now run:
PING
Output:
PONG
Congratulations! You've just verified a live server-client connection. Now try a quick key-value pair:
SET name "Redis Learner"
GET name
Output:
OK
"Redis Learner"
Example 3: Start server in daemon mode
If you prefer not to occupy a terminal, start Redis as a background daemon:
redis-server --daemonize yes
Then check if it's running:
redis-cli ping
You should get PONG without needing a separate terminal. The server is now running invisibly in the background.
Example 4: Python client connection (bonus)
Once the server is running, you can also connect from Python using the redis library:
import redis
# Connect to the default localhost:6379
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
# Ping the server
print(r.ping()) # True
# Set and get a key
r.set('greeting', 'Hello from Python!')
print(r.get('greeting')) # b'Hello from Python!'
Compare options / when to choose what
| Method | Use case | Pros | Cons |
|---|---|---|---|
Foreground (redis-server) |
Quick development / debugging | Easy to see logs; hit Ctrl+C to stop | Blocks terminal; not for production |
Daemon mode (--daemonize yes) |
Local demos or single-user dev | No terminal blocking; still simple | Less control over logs; need separate command to stop |
| System service (systemd, launchd, etc.) | Production or persistent server | Auto-start on boot; managed by OS | More setup; requires root/admin access |
| Docker container | Reproducible environments / CI | Isolated; easy version changes | Overkill for simple local use |
When to choose what: - Use foreground when you're learning or debugging — you see real-time logs. - Use daemon when you want a persistent Redis server in the background but don't need full production orchestration. - Use system service or Docker when you need the server to survive reboots or be shared across multiple projects.
Troubleshooting & edge cases
"Could not connect to Redis at 127.0.0.1:6379: Connection refused"
This means the server isn't running, or it's on a different port/host. Check:
* Is redis-server running? (ps aux | grep redis-server on Unix, tasklist | findstr redis on Windows)
* Did you start it with a custom config that changes the port? Default is 6379.
* Are you trying to connect from a different machine? Redis by default binds to 127.0.0.1 — it's local only. To allow remote connections, set bind 0.0.0.0 in redis.conf (not recommended without firewall).
"MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk"
This happens when Redis can't write snapshot files. Common causes: disk full, wrong permissions on the data directory. Fix by freeing disk space or changing the dir in redis.conf.
Server starts but client hangs
Check for firewall rules blocking port 6379. On Linux:
sudo ufw status # check if firewal is active
sudo ufw allow 6379 # allow Redis port temporarily (not for production)
Also ensure you haven't accidentally set a requirepass on the server — if so, use redis-cli -a yourpassword.
Multiple instances conflict
If you already have a Redis server running on port 6379, starting another will fail with Could not bind to TCP port 6379: Address already in use. Either stop the existing instance or start a new one on a different port:
redis-server --port 6380
redis-cli -p 6380
What you learned & what's next
Now you know how to start the Redis server and connect with the client. You've seen:
- The core idea: Redis is a client-server system — the server must be running before clients can interact.
- How to start: Running
redis-serverin foreground or daemon mode, verifying withredis-cli ping. - How to connect: Using
redis-clior Python'sredislibrary. - Common pitfalls: Connection refused errors, port conflicts, permission issues.
- When to choose: Foreground for debugging, daemon for local dev, system service or Docker for production.
You're ready for the next lesson: Working with Redis Strings — where you'll practice the most basic data type using the client you just learned to connect.
Pro tip: Always stop Redis gracefully with SHUTDOWN or redis-cli shutdown to avoid data loss. Never kill -9 the process.
Practice recap
- Start Redis in daemon mode:
redis-server --daemonize yes. 2. Verify withredis-cli ping. 3. Set a keytestwith valuehelloand retrieve it. 4. Stop Redis withredis-cli shutdown. This confirms you can fully manage the server life cycle.
Common mistakes
- Running
redis-clibeforeredis-server— you'll get 'Connection refused' because no server is listening. - Forgetting that
redis-serverblocks the terminal in foreground mode — opening a second terminal to runredis-cliis the fix. - Thinking 'redis-cli ping' is enough to start the server — it only checks the server; you must start the server separately.
- Starting Redis on a non-default port (e.g., 6380) but then trying to connect without
-p 6380flag, leading to connection refused.
Variations
- Use
redis-server --port 6380to run a second instance on an alternative port for testing separate data sets. - Use
redis-server /path/to/redis.confto start with a custom configuration file instead of default settings. - Use
redis-cli -h 192.168.1.100 -p 6379 -a secretto connect to a remote server with password authentication.
Real-world use cases
- A web application starts Redis in daemon mode on a staging server, allowing developers to test caching patterns before production deployment.
- A CI/CD pipeline uses
redis-serverinside a Docker container to run integration tests against a temporary Redis instance. - A system administrator configures Redis as a systemd service to automatically start on boot, providing a persistent session store for a login service.
Key takeaways
- Redis is a client-server architecture — always start
redis-serverbefore usingredis-cli. - Use
redis-cli pingas the simplest test to verify a live connection. - Foreground mode is great for learning; daemon mode or system services are for production.
- Connection refused usually means the server isn't running or is on a different port/host.
- Graceful shutdown with
redis-cli shutdownprevents data corruption. - You can run multiple Redis instances on different ports using the
--portflag.
Keep learning
Related tutorials, quizzes, and articles for this topic.
Discussion
Questions, corrections, and tips help everyone reading this page.
0 comments
Add a comment
No comments yet — start the thread.