What is Redis?
Redis is a very fast data store that keeps information in memory (RAM). RAM is the computer's quick short-term memory. Because it avoids the slower disk, Redis answers in tiny fractions of a second. Websites use it as a cache, which is a place to keep copies of things used often, like page parts or search results. It is also used for sessions (remembering who is logged in) and job queues.
Steps on Ubuntu or Debian
- Connect to your server with SSH.
- Update the package list:
sudo apt update
- Install Redis:
sudo apt install redis-server -y
- Start it and make it start at boot:
sudo systemctl enable --now redis-server
Steps on AlmaLinux, Rocky or CentOS
- Install Redis:
sudo dnf install redis -y
On older CentOS you may need yum and an extra package source.
- Start it and make it start at boot:
sudo systemctl enable --now redis
Test that it works
- Open the Redis command tool:
redis-cli
- Type
ping. It should answerPONG. - Store and read a value:
set mykey "hello"
get mykey
The first line saves a value. The second line reads it back.
- Type
exitto leave.
Keep it safe
Warning: do not leave Redis open to the internet. Attackers scan for open Redis servers.
- Back up the settings file. Its path is
/etc/redis/redis.confon Ubuntu, or/etc/redis.confon Alma and Rocky. - Open the file and make sure this line is set, so only the server itself can connect:
bind 127.0.0.1
- Add a password with the
requirepassline:
requirepass YourStrongPasswordHere
- Restart Redis, using the service name from earlier steps:
sudo systemctl restart redis-server
Tip: Apps like WordPress and Laravel can use Redis for caching once you install a connector. Redis uses RAM, so keep an eye on your memory.
Quick recap
- Redis is a fast in-memory store, often used for caching.
- Install it with apt or dnf and start the service.
- Test with
redis-cliandping. - Keep it private with bind and a password.