Starting Redis and Connecting with redis-cli
Before any of Wordcraft's counters or leaderboards can exist, you need a Redis server running and a way to type commands at it. There are several ways to install Redis, but they all end at the same place: a server listening on a port and a client that talks to it.
The rule
Start the server, connect with redis-cli, and PING until it says PONG.
Start a server. Pick whichever route suits your machine:
# Docker: nothing to install except Docker itself
docker run -d --name redis -p 6379:6379 redis
# macOS with Homebrew
brew install redis
brew services start redis
# Debian or Ubuntu
sudo apt install redis-server
# Any system: run the server binary directly
redis-serverDocker is the quickest to try and the easiest to remove. A package manager (Homebrew, apt) installs Redis as a system service that starts with the machine. You can also download the source release and build it with make, or use a pre-compiled binary if one is packaged for your platform; either way you then start the server by running redis-server. By default the server listens on port 6379.
Connect. redis-cli is the command-line client that ships with Redis. With no options it connects to 127.0.0.1 on port 6379; -h and -p choose another host or port. In Docker you can run the client inside the container:
docker exec -it redis redis-cliCheck it. Your first command should be PING:
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET greeting hello
OK
127.0.0.1:6379> GET greeting
"hello"The prompt shows the host and port you are connected to. Command names are not case-sensitive (ping works too), but key names are: greeting and Greeting are different keys.
The shortcut
When something does not work, walk the chain in order: server, port, client, PING. Every step depends on the one before.
Server
Is a Redis server running?
docker ps(orbrew services list) shows it.
Once connected, two habits save time. redis-cli remembers your command history (press the up arrow), and typing HELP SET shows the syntax of any command. You can also run a single command without entering the prompt, as in redis-cli GET greeting, which is handy in scripts. To stop a Docker server, run docker stop redis; docker start redis brings it back.
Drills
Answer fast — trust the rule.
What does a healthy server reply to PING?
Which port does Redis listen on by default?
You ran docker run -d --name redis redis and redis-cli on your laptop cannot connect. What is missing?
After SET greeting hello, what does GET Greeting reply?
Remember
- Start the server, connect with redis-cli, and PING until it says PONG.
- Debug in order: server, port, client, PING.
- Commands ignore case; keys do not. The default port is 6379.
