Guide to Setup Valkey as a Cache Layer to Replace Redis and Optimize 50% VPS Costs
Valkey, an open-source fork of Redis, delivers comparable performance with significantly lower operational costs. This guide demonstrates how to deploy Valkey as a complete Redis...
Valkey, an open-source fork of Redis, delivers comparable performance with significantly lower operational costs. This guide demonstrates how to deploy Valkey as a complete Redis replacement on a VPS, enabling businesses to reduce VPS expenses by up to 50% without sacrificing data retrieval speed. With its simple architecture, full Redis command compatibility, and enhanced efficiency, Valkey is ideal for systems requiring cost optimization while maintaining high performance.
Why Choose Valkey Over Redis?
Valkey is an open-source project developed by Redis Labs (now Redis Inc.) to continue Redis development with a more sustainable and open approach. Valkey maintains full compatibility with Redis, including its protocol, commands, and configuration, but is optimized for modern systems. It features multi-threading, reduced memory usage, and I/O optimizations, which lower CPU and RAM consumption, thereby reducing VPS operational costs. Many organizations have transitioned from Redis to Valkey and reported up to 50% savings on VPS rental fees due to higher performance with fewer resources.
Prerequisites and Environment Setup
To deploy Valkey, you need a VPS with at least 2GB RAM and 1 CPU core, though 4GB RAM is recommended for stable performance. You can use NVMe Cloud VPS for Docker, Nginx & Databases for reliable and powerful resources. Ensure your operating system is Ubuntu 20.04 or 22.04, and you have root access or sudo privileges.
Prepare the following tools:
- SSH client (e.g., OpenSSH or PuTTY)
- Linux terminal or shell
- Git (if downloading source code)
Install Valkey
Valkey can be installed via system packages or from source. Below is the installation guide using the Ubuntu package manager:
sudo apt update
sudo apt install -y build-essential tcl
wget https://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
sudo make install
After successful compilation, create a configuration directory and copy the default configuration file:
sudo mkdir -p /etc/valkey
sudo cp redis.conf /etc/valkey/valkey.conf
Open the configuration file for editing:
sudo nano /etc/valkey/valkey.conf
Adjust the following key parameters:
- port: Set to the default 6379
- daemonize: Set to yes to run as a background process
- requirepass: Set a password for security (if needed)
- maxmemory: Set a memory limit (e.g., 1GB)
- maxmemory-policy: Set a data eviction policy (e.g., allkeys-lru)
Start and Verify Valkey
After configuration, start Valkey:
sudo valkey-server /etc/valkey/valkey.conf
To verify Valkey is running, use the command:
valkey-cli ping
If it returns "PONG", Valkey is operational. You can check status with:
valkey-cli info
To monitor performance, use tools like Secrets to Running 50 Docker Containers Smoothly on a 4GB RAM VPS to track system resources.
Switching from Redis to Valkey
Since Valkey is fully compatible with Redis, migration is straightforward. Simply update your application’s connection address from Redis to Valkey. For example, in a Node.js application:
const redis = require('redis');
const client = redis.createClient({
host: 'localhost',
port: 6379
});
No changes are needed to Redis commands. All commands such as SET, GET, HSET, HGET, LPOP, RPOP, etc., work identically to Redis.
Troubleshooting
If Valkey fails to start, check the logs:
sudo tail -f /var/log/valkey.log
If you encounter memory issues, adjust the maxmemory and maxmemory-policy settings in the configuration file. If connection fails, verify that firewall rules allow port 6379.
References
Valkey official site: https://valkey.io
Redis official site: https://redis.io
Installation guide on Ubuntu: https://redis.io/docs/getting-started/installation/
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
