Moving from Redis to Valkey
By Melroy van den Berg
- 6 minutes read - 1186 wordsThis guide is focus on moving from Redis to Valkey on my Ubuntu Server 24.04. There is no official documentation on how to setup Valkey via the binary, so this guide will help you to get started with Valkey. Which in my case will replace my Redis servers.
If you use Docker, you can simply use the Docker image: valkey/valkey:8.0
from Dockerhub (always use tagged versions, at this moment 8.0
is the latest stable version, or more specific: 8.0.1
)
Assumption: I do assume you have some basic knowledge of GNU/Linux and how to use the command line.
Why Valkey?
Valkey is an in-memory data store that is designed to be a drop-in replacement for Redis (in case you were using Redis before). Valkey is a fork of Redis. The data is stored using key-value pairs (hence the name Valkey). The keys are unique identifiers, and the values can be of different types (strings, lists, sets, etc).
Both Valkey and Redis are thus in-memory data structure stores, that can be used as a database and/or as a cache (persistent by default). Valkey is officially part of the Linux Foundation.
Valkey uses the same protocol as Redis.
Wait, what is Redis?
Redis is an in-memory data structure store. It’s used for storing and retrieving data in a fast and efficient manner from memory rather than from disk. Redis is used a lot in applications to speed up the application (eg. caching).
Redis is deployed in large corporations but also in small startups and many open-source projects.
Licenses
Valkey is a real open-project under the BSD 3-Clause License, while Redis changed their license to dual license, namely the “Redis Source Available License v2” and “Server Side Public License”. Note: Redis calls it “source-available software”, which is not the same as “open-source software”. Both of which are NOT compatible with the OSI definition of open-source software. Do not get fooled by Redis! Hence the reason why I’m not using Redis anymore.
There aren’t many how-to articles about Valkey, so I decided to write this guide.
Note: There are also alternatives like KeyDB (last release is 1 year ago).
Install Valkey
Valkey recently provided backported binaries for Ubuntu 24.04 in the official Ubuntu Universe repository.
However, this is not the latest version of Valkey! The latest version is 8.0.1
(at the time of writing), and installing valkey-server via APT will install version 7.2.5
:
sudo apt install valkey-server
Luckily, they do have a binary download from the official download page, the latest link allowed me to download: Valkey 8.0.1 Focal for x86_64.
Although I’m using Ubuntu 24.04, the focal binary works fine!
Well, after I created two pull requests that fixes the binaries: PR #1106 and PR #1107, which are part of Valkey patch release 8.0.1
.
Installation is pretty straight forward, just extract the file and move the files to /usr/local
:
# Untar
tar -xzf valkey-8.0.1-focal-x86_64.tar.gz
# Go to directory
cd valkey-8.0.1-focal-x86_64/
# Copy files
sudo cp -R . /usr/local/
Note: Don’t try to install via APT and also install the binary from the download page. Just pick one or the other.
Prepare users and directories
Let’s create a dedicated valkey
user and group:
sudo groupadd valkey
sudo useradd -g valkey valkey
Create a /var/lib/valkey
directory, we will use it later!
sudo mkdir -p /var/lib/valkey
sudo chown -R valkey:valkey /var/lib/valkey
And also create a /var/run/valkey
directory, you will later need for PID file as well as storing the socket file:
sudo mkdir -p /var/run/valkey
sudo chown -R valkey:valkey /var/run/valkey
Setup systemd service
Since we’re using Valkey as a standalone binary, we’ll need to create our own systemd service file in order to start Valkey on boot.
Let’s create a systemd service file within the: /usr/lib/systemd/system
directory. Luckily, we can find a systemd service example in the official Valkey repository, using the unstable
branch. Which doesn’t mean this file is unstable, but you will just get the latest version.
sudo nano /usr/lib/systemd/system/valkey-server.service
With the following content:
[Unit]
Description=Valkey data structure server
Documentation=https://github.com/valkey-io/valkey-doc
AssertPathExists=/var/lib/valkey
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/valkey-server /etc/valkey/valkey.conf --supervised systemd --daemonize no
LimitNOFILE=10032
NoNewPrivileges=yes
OOMScoreAdjust=-900
PrivateTmp=yes
Type=notify
TimeoutStartSec=infinity
TimeoutStopSec=infinity
UMask=0077
User=valkey
Group=valkey
WorkingDirectory=/var/lib/valkey
[Install]
WantedBy=multi-user.target
Once you created the systemd file, like above, we reload the systemd manager:
sudo systemctl daemon-reload
Create Valkey Configuration file
Now that we have the systemd service file, we can create a configuration file.
And create the config directory:
sudo mkdir -p /etc/valkey
sudo chown -R valkey:valkey /etc/valkey
I will use the conf file from the official Valkey repository again: valkey.conf (from the unstable
branch).
sudo nano /etc/valkey/valkey.conf
With the RAW content from the valkey.conf file mentioned earlier above.
I made several changes to the configuration file thus far:
# Change the PID file directory location (mainly to avoid permission issues)
-pidfile /var/run/valkey_6379.pid
+pidfile /var/run/valkey/valkey_6379.pid
# Enable Unix socket file with 777 permissions (if you want)
+unixsocket /var/run/valkey/valkey.sock
+unixsocketperm 777
# Set a memory limit
+maxmemory 1GB
# Set a memory limit policy
+maxmemory-policy allkeys-lru
# Optionally enable io-threads (if you want)
+io-threads 4
# Optionally decrease the keep alive (again if you want)
+tcp-keepalive 120
Finally, set the rights correctly on the file:
sudo chown valkey:valkey /etc/valkey/valkey.conf
Starting Valkey
Valkey configuration by default will use TCP port 6379, which is the default port for Redis as well. Meaning if you are still running running Redis, stop the Redis service first.
Start Valkey via:
sudo systemctl start valkey-server
Enable during start-up:
sudo systemctl enable valkey-server
Finally, check if the server runs correctly:
sudo systemctl status valkey-server
Should look something like this:
Can you connect to the server? Let’s try that as well if you want:
valkey-cli
Now you can type for more details about this specific server:
INFO server
Cool huh? Welcome to Valkey! I’m happy I’m no longer running Redis anymore.
Assuming your application is using Valkey (which, again, can utilize the Redis RESP protocol), and has inserted some data, you can then verify whether the data is present:
# Connect to the server, using the CLI
valkey-cli
# Now type:
INFO KEYSPACE
If there is any data stored, it should give you the number of keys stored in the database (db0
). For example:
# Keyspace
db0:keys=46285,expires=45885,avg_ttl=2268615808
Performance
Both Redis & Valkey support IO threads on both write and reads. Valkey should give better performance in Valkey 8.0 as well as improved reliability and replication. See also their 1 million RPS blog post.
That being said, I didn’t perform benchmarks (or load tests) across Redis and all their alternatives, so I can’t come to any conclusions in terms of performance. I can only share the numbers I see from what I get from the Valkey benchmark tool (valkey-benchmark
) for now:
Summary:
throughput summary: 97087.38 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.269 0.080 0.255 0.391 0.495 0.847
Details: This benchmark test above is performed on a single Valkey instance, running on an Ubuntu Server 24.04 VM inside Proxmox, using consumer grade hardware (AMD platform with DDR4 memory). I didn’t change the io-threads
settings.
Questions?
If you have any questions, remarks or suggestions, please use the comment section below.