Introduction
Redis is an open-source, in-memory data store that's super fast and often used as a cache, database, or message broker. It's a great tool for improving application performance because it stores data in memory, making access lightning-quick compared to traditional databases.
You’ll typically see Redis used to cache web pages, manage session states, or even queue background tasks in modern web apps. It supports a wide variety of data types like strings, hashes, lists, sets, and more, plus it can persist data to disk if needed.
If you’re running a high-performance application on Ubuntu or Debian, Redis can be a game-changer in reducing latency and offloading your main database.
Prerequisites
Before installing Redis, there are a few key prerequisites every user should be aware of:
Root or sudo access – You need administrative privileges to install packages and manage services on the system.
Updated system – Your Ubuntu or Debian OS should be up to date to avoid compatibility issues with dependencies.
Run sudo apt update –y && apt upgrade –y to update your system.
Minimal system requirements
CPU: A single-core processor (Redis is single-threaded for most operations).
RAM: At least 256 MB, though 1 GB or more is recommended for anything beyond testing.
Disk space: At least 50 MB for Redis itself, but more depending on how much data you plan to persist.
Since Redis is lightweight, however performance depends heavily on available RAM since it operates in-memory.
Installation
1. If you have not updated your system yet, run the following command, if you have, skip to the next step
sudo apt update && sudo apt upgrade -y
2. Install Redis. It will install the Redis service and its dependencies.
sudo apt install redis-server -y
3. Check if Redis is running. You should see it marked as "active (running)".
sudo systemctl status redis
3.1. If the Redis did not start, run the following command:
sudo systemctl start redis
3.2. Enable Redis on boot:
sudo systemctl enable redis-server
4. Test Redis. Try a simple ping with the Redis CLI. Expected output: PONG That means it’s running and responding correctly.
redis-cli ping
Securing and Configuring Redis
1. Configure Redis to accept only local connections. By default, Redis only listens on 127.0.0.1 (localhost). You can confirm this:
sudo nano /etc/redis/redis.conf
1.1. Look for: bind 127.0.0.1 -::1
If it's set to 0.0.0.0, change it back to 127.0.0.1 unless you need remote access. You can quickly search the file content by pressing Ctrl + W and entering the queried phrase.
1.2. If you need more than one network which can be accessed, separate them with space, just like in the example:
bind 127.0.0.1 167.231.232.71 162.54.23.1
2. Set a strong Redis password. Still in redis.conf, look for this line:
# requirepass foobared
2.1. Uncomment it and set a strong password:
requirepass yourStrongPasswordHere
2.2. Save and exit (Ctrl+X), then restart Redis:
sudo systemctl restart redis
2.3. Test the password, you should see OK after the input:
redis-cli
127.0.0.1:6379> auth yourStrongPasswordHere
OK
2.4. Check if Redis is functioning correctly by sending a test message:
set test "Test Redis"
2.5. After receiving OK write following command to check. If Redis is functioning correctly, you should see your message:
get test
Test Redis
3. Disable or rename dangerous commands. There are multiple Redis commands which can change or delete your database tables and records. They are useful for administering, however non authorized user can exploit them leading in fatal error. For example:
FLUSHALL – deletes all keys and data in your entire Redis instance.
FLUSHDB – wipes data in the current database.
SHUTDOWN – shuts down the Redis server without saving the data.
DEL – removes one or multiple keys from your current database.
RENAME – rename a key in the currently selected database.
SAVE – saves a dataset to the server’s storage while blocking other running processes.
To disable or rename them, enter redis.conf file:
sudo nano /etc/redis/redis.conf
Look for the section named “###SECURITY###” and and a command string “rename-command” There you can either rename or disable. Let’s change command “FLUSHALL”
rename-command FLUSHALL IDOFLUSH
It will rename command “FLUSHALL” to “IDOFLUSH”. The functionality remains the same.
Now, let’s disable command “SHUTDOWN”:
rename-command SHUTDOWN “”
Save the file (CTRL + X) and restart Redis:
sudo systemctl restart redis
Login to Redis service with a command “redis-cli
” and try running commands with your made changes.
Using Redis with WordPress, Prestashop, Opencart
1. Install PHP Redis extension:
sudo apt install php-redis -y
1.1. Restart PHP:
sudo systemctl restart apache2
Enabling Redis with WordPress
1. Install a Redis caching plugin like “Redis Object Cache”
2. Add to “wp-config.php”:
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_PASSWORD', 'yourStrongPasswordHere');
3. Activate the plugin and click “Enable Object Cache”
Enabling Redis with PrestaShop
1. Use a PrestaShop module like "Redis Cache" or "Page Cache Ultimate"
2. Configure Redis server in the module settings:
Host: 127.0.0.1
Port: 6379
Password: yourStrongPasswordHere
Enabling Redis with OpenCart
1. Modify the config to use Redis session handler. In config.php and admin/config.php, add:
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://127.0.0.1:6379?auth=yourStrongPasswordHere');
Conclusion
Redis is a powerful and lightweight in-memory data store that significantly boosts performance for web applications through caching and fast data retrieval.
Setting it up on Ubuntu or Debian is straightforward, requiring just basic terminal knowledge and minimal system resources. With proper configuration and integration.
Redis can enhance CMS platforms like WordPress, PrestaShop, and OpenCart by caching queries, sessions, and objects.