KeyDB is a high performance fork of Redis with a focus on multithreading, memory efficiency, and high throughput. KeyDB, a Redis alternative, still has full and absolute compatibility with Redis and straightforward clustering and sharding without the need for Sentinel and other auxiliary software. By the end of this guide, you will have a KeyDB database running on Northflank. Let’s get to it!
Create a new service.
Select Deployment as the Service type.
Select external image and
eqalpha/keydb:latest
as image path.Configure the 6379 TCP port on the service.
- KeydDB service will be only available internally. In case you need to connect to it from your machine, Northflank forwarder will be required.
Start the forwarding of the service through the Northflank CLI.
Using the
redis-cli
, for a service calledkeydb
, connect to it using the following string:
redis-cli -h keydb
Once connected you can start running commands. For example:
set hello bye
get hello
In order to enable authentication you can rely on the requirepass parameter when starting the server.
First let’s create a proper password string. Jump to the
Environment
tab in the Service Dashboard and create a new one through theGenerate secret values
. Name the new environment variableKEYDB_PASSWORD
. Commit the changes.Now go to the
CMD Override
tab.Once there, edit the command through the
Edit commands
button.Enable the
Use override
option. Then, replace the CMD Override text field with the following command:/bin/sh -c “keydb-server /etc/keydb/keydb.conf --requirepass $KEYDB_PASSWORD”
- The `/bin/sh` is required for the KEYDB_PASSWORD environment variable to be correctly processed as the `requirepass` argument value.
Commit the changes through the
Save & restart button
.Wait for the container to start up again.
You may have to restart the forwarder given that the container was restarted. Once the forwarder is running and using the
redis-cli
, use the following arguments to connect to it:$KEYDB_PASSWORD=<copy value from northflank ui> redis-cli -h keydb -a $KEYDB_PASSWORD
Check that you’re able to run commands as shown previously.
- You may notice that when querying the keys created previously they no longer exist. This is because persistence for this container is not enabled.
In order to avoid data loss between restarts or outages, we first need to provision persistence storage to our service.
Head over to the
Volumes
tab and add a new volume.Select proper storage space according to your requirements. In this case we’re going to use 5GB.
The Keydb container uses the
/data
path to store all of its data. Make sure to put/data
as theContainer mount path
.Confirm the changes through
Create & attach volume
.
KeyDB by default will use snapshot persistence, which stores changes on a file after a certain number of commands or a certain amount of time has elapsed.
This is not very durable as the latest changes written to KeyDB may not get written to the snapshot file. Read more on KeyDB persistence on their docs.
To have a more durable persistence, we use the append only mode, which appends changes on a file each time the data set has been changed.
In order to enable it we have to head over to the
CMD Override
tab and then pass the--appendonly yes
argument to the initial command.The final version including authentication is as follows:
/bin/sh -c "keydb-server /etc/keydb/keydb.conf --requirepass $KEYDB_PASSWORD –appendonly yes"
Commit the changes
Wait for the container to start up correctly.
Connect to it using the forwarder or a Redis client, for example Redis Commander. This guide shows you how to deploy Redis Commander on Northflank.
Start running commands that store data on KeyDB.
Perform a restart.
Connect again and verify that the data is still present on KeyDB.
Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.
- Deployment of Docker containers
- Create your own stateful workloads
- Persistent volumes
- Observe & monitor with real-time metrics & logs
- Low latency and high performance
- Multiple read and write replicas
- Backup, restore and fork databases