VALKEY-MIGRATION(7)
π valkey-migration(7) β straight outta the Valkey Manual π
okay bestie, buckle up π«Ά this is the glow-up guide: how to move your whole life from Redis to Valkey, and honestly? it's giving upgrade, not sidegrade.
β¨ NAME β¨
valkey-migration β migrating from Redis to Valkey, no cap π
πΈ DESCRIPTION πΈ
So like, this is the migration guide from Redis open source versions over to Valkey. You're gonna learn how to migrate a standalone Redis server instance and a Redis Cluster. Both of them. We're doing the whole thing.
The steps in here are written for Redis server and Valkey deployed in Docker, but lowkey they should also apply to other deployments too. And if you need to actually install Valkey first, go peek at valkey-installation(7) for the installation options, mwah π
π Why to migrate to Valkey?
- Valkey is the vendor-neutral and open-source software π
- Enhanced performance with multi-threading and dual-channel replication π₯
- Improved memory efficiency by using one dictionary per slot in cluster mode and embedding keys in dictionaries β¨
π¦ Migration compatibility matrix
You can migrate a Redis server to Valkey. Valkey is compatible with Redis OSS 7.2 and all earlier open source Redis versions, because Valkey 7.2.4 is literally a fork of Redis 7.2.4. So migrating from any open source Redis version to Valkey? That's effectively an upgrade. iconic behavior fr fr.
NOTE: In this guide, whenever a reference to aredis-cliorvalkey-clicommand is provided, the reference will only point to the Valkey version of the documentation. iykyk.
Okay so this next part is important. Redis Community Edition (CE), versions 7.4 and later, are not open source and the data files are not compatible with Valkey. π It may be possible to migrate the data to Valkey from proprietary Redis versions and other Redis-like software, but it requires another method and is not covered by this document. So don't come for me, it's just not in here.
The following table provides migration options depending on the Redis version you run:
- Redis
OSS 2.x - 7.2.xβ Valkey7.2.xβ - Redis
OSS 2.x - 7.2.xβ Valkey8.0β - Redis
CE 7.4βn/aπ
π Migrate a standalone instance
To migrate a standalone Redis server to Valkey, you've got options, bestie. Pick your fighter:
- Physical migration by copying the most recent on-disk snapshot from the Redis server to Valkey and starting Valkey server with it π
- Setting up replication between Redis and Valkey π§
- Migrating specific keys π
The example migration steps are provided for Redis 7.2.5 and Valkey version 7.2.6.
Also note: Redis and Valkey Docker containers are considered stand-alone servers, if they are not part of a cluster. Just so we're clear.
π₯ Physical migration
This is the easiest and fastest migration method, periodt. You make a fresh snapshot of your Redis instance and copy it over to Valkey. Valkey reads the data from the snapshot on startup and restores its contents into memory. But the tradeoffs, bestie, we gotta talk about them:
- The downtime to shutdown Redis and wait for Valkey to load the data β³
- Potential risk of data loss on instances with heavy writes. To prevent it, you must disconnect all active connections before starting the migration π¨
To perform a physical migration:
- Disconnect all active connections to the Redis instance.
- Connect to your Redis container using
redis-cli, and check the number of keys, using theINFO KEYSPACEcommand. This will be used later to verify that the entire database has been successfully migrated. In this example,keys=6286indicates that there are 6,286 keys in the database.
$ redis-cli -h 127.0.0.1 -p 6379
redis 127.0.0.1:6379> INFO KEYSPACE
# Keyspace
db0:keys=6286,expires=0,avg_ttl=0
- Check the configuration for the directory (
dir) where Redis stores its database files and the name of the database file (dbfilename). In this example, Redis saves the backup into the/data/dump.rdbfile
NOTE: If your Redis Docker container /data directory is mounted to a directory on your host, the RDB file is also written to that host directory.
redis 127.0.0.1:6379> CONFIG GET dir dbfilename
1) "dir"
2) "/data"
3) "dbfilename"
4) "dump.rdb"
- Create the backup file. Since all active connections have been disconnected for this example, the
redis-clisave(3valkey)command can be used to create the backup file.
redis 127.0.0.1:6379> SAVE
OK
- Exit
redis-cliby pressing CTRL-D or typingexit. - Create a directory on your host to which you will mount the
/datadirectory of the Valkey container. - Copy the RDB file from Redis to Valkey, using one of the following:
- If the Redis and Valkey containers are both mounted to a host directory:
Copy the RDB file from the host directory mounted to the Redis container to the host directory being mounted to the Valkey container.
- If the Redis container is not mounted to a host directory but the Valkey container is:
Use docker cp to copy the RDB file from within the Redis container to the host directory that will be mounted to your Valkey container.
NOTE: You may also want to copy the RDB file to a second location as a backup.
docker cp redis-container-name:/dir-name/dbfilename <path/on/host>/dbfilename
- Stop the Redis server.
- Start Valkey:
NOTE: If you enabled AOF in your Valkey configuration, disable it on the first start. Otherwise, the copied RDB file will not be imported into Valkey. π
Run the following command:
docker run -d --name valkey-container-name -v <path/on/host>:<path/in/Valkey/container> image-name
- To verify that the data has been successfully migrated, determine the number of keys in the Valkey database. If the migration is successful, then the number of keys in the Valkey database match the number of keys in the Redis database that you obtained in step 2:
$ docker exec -it somevalkey valkey-cli
valkey 127.0.0.1:6379> INFO KEYSPACE
# Keyspace
db0:keys=6286,expires=0,avg_ttl=0
- To exit
valkey-cli, press Ctrl-D or typeexit.
π Replication
To minimize the downtime during migration, you can use replication. Both Redis and Valkey allow replaying data on another server to handle the workload. it's giving teamwork π«Ά
In this scenario we will configure Valkey to be the replica of Redis. For illustrative purposes, both Redis and Valkey are running in separate Docker containers connected to the same network.
- Retrieve the IP address of the Redis container. Replace the
myredisplaceholder with the name of your container. In this example,172.17.0.2is returned as the IP address of themyrediscontainer.
$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myredis
172.17.0.2
- Determine the port on which your Redis container is exposed. Note that for clarity, not all of the fields are shown in the response. In this example, the
myrediscontainer is exposed on port6379.
docker container ls
CONTAINER ID ... PORTS NAMES
bffc575f261a ... 6379/tcp myvalkey
ab18318ce820 ... 6379/tcp myredis
- Connect to your Valkey container and start the
valkey-clito configure replication using thereplicaof(3valkey)command. In this example, the Redis IP address is172.17.0.2and the port is6379. Replace with the IP address and port of your Redis container obtained in steps 1 and 2.
docker exec -it myvalkey valkey-cli
valkey 127.0.0.1:6379> REPLICAOF 172.17.0.2 6379
OK
- Check the replication status in Valkey using the
INFO REPLICATIONcommand. Ifmaster_link_status:upis present, then the Redis and Valkey servers are synchronized.info(3valkey)describes the different output fields.
valkey 127.0.0.1:6379> INFO REPLICATION
# Replication
role:slave
master_host:172.17.0.2
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
....
- Once Redis and Valkey are synchronized, verify that your applications connect to Valkey and shut down your Redis instance.
NOTE: Since the Redis 7.0 release, theSHUTDOWNcommand waits for a time period, set by theshutdown-timeoutconfiguration variable, for any lagging replicas to sync. There may be potential data loss in the case where there are writes active on the Redis primary while it is syncing with the replica. π¬
You can shut down Redis in one of the following ways:
- Using
redis-cli:
$ redis-cli SHUTDOWN
- If Redis was started directly in the foreground (using
redis-server), you can simply stop it by pressing Ctrl-C in the terminal where it is running.
- In your Valkey container, stop the Valkey replication using the
REPLICAOFcommand withNO ONEas the options:
valkey 127.0.0.1:6379> REPLICAOF NO ONE
OK
- You can verify that replication has stopped by running the
valkey-clicommand,INFO REPLICATION. If you seerole:masterandconnected_slaves:0, then the Valkey container is now the master and is no longer connected to the Redis server.info(3valkey)describes the different output fields.
127.0.0.1:6379> INFO REPLICATION
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:8d48c4667129cdb5933f9a12a1d5e6a24899602b
master_replid2:602b7046ada6d2d6f0e89657e646d5932cc42791
master_repl_offset:1336
second_repl_offset:1337
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1336
NOTE: If not for backward compatibility, the Valkey project no longer uses the words "master" and "slave". Unfortunately, in this command these words are part of the protocol, so we'll be able to remove such occurrences only when this API is naturally deprecated. not me being stuck with legacy naming π
β Migrate specific keys
Both physical migration and replication migrate the entire keyspace over to Valkey.
There may be cases when you need to migrate only a specific set of critical keys. The redis-cli command, migrate(3valkey) is used to migrate one or more keys.
Requirements for this example:
- The Redis and Valkey Docker containers are on the same network and can communicate with each other. π
- The Redis and Valkey containers are running without authentication. π
okay bestie, buckle up, because this part is the actual doing it part. perform the following steps:
- first you gotta figure out which keys you're moving. in this little demo, the
messageandmydatakeys are getting yeeted out of themyrediscontainer, andredis-cliis what we use to peek at their current values. look:
$ docker exec -it myredis redis-cli
redis 127.0.0.1:6379> GET message
"Hello Valkey"
redis 127.0.0.1:6379> HGETALL mydata
1) "name"
2) "Alice"
3) "age"
4) "33"
5) "country"
6) "Brazil"
7) "favorite food"
8) "beans"
- now go get the IP address of your Valkey container. swap
myvalkeyfor whatever your Valkey container is actually called, obviously π
$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myvalkey
172.21.0.3
- next, start up
valkey-cliinside your Valkey container and grab the database number withINFO KEYSPACE. in this example the database number is0(so,db0). periodt.
valkey 127.0.0.1:6379> INFO KEYSPACE
# Keyspace
db0:keys=3,expires=0,avg_ttl=0
NOTE: if you haven't migrated or added any data to your Valkey database yet, then theINFO KEYSPACEcommand will not return any database number. no biggie β you can just use0for theMIGRATEcommand in step 4. π«Ά
- from the Redis server, run the
MIGRATEcommand:
MIGRATE valkey-ip valkey-port <key | ""> valkey-db-number timeout-value [COPY] [REPLACE] [AUTH password | AUTH2 username password] [KEYS key [key ...]]
so like, say you wanna migrate the message and mydata keys over to the Valkey instance sitting at IP address 172.21.0.3 and port 6379 β the command would look a lil something like this:
redis 127.0.0.1:6379> MIGRATE 172.21.0.3 6379 "" 0 10 COPY REPLACE KEYS message mydata
and here's the breakdown of what all that means, bestie:
""= indicates that we are migrating multiple keys. you can use a key name here instead if you're only migrating a single key.0= the database number.10= the maximum idle time, in milliseconds, allowed when communicating with the destination server.COPY= do not remove the key from the Redis database.REPLACE= replace existing key on the Valkey database.KEYS= we are migrating multiple keys, and it is followed by the key names.
- dip out of
redis-cliby pressingCtrl-Dor typingexit. bye bestie π - connect to Valkey and check that your migrated keys actually landed. replace
myvalkeywith the name of your Valkey container:
$ docker exec -it myvalkey valkey-cli
valkey 127.0.0.1:6379> GET message
"Hello Valkey"
valkey 127.0.0.1:6379> HGETALL mydata
1) "name"
2) "Alice"
3) "age"
4) "33"
5) "country"
6) "Brazil"
7) "favorite food"
8) "beans"
....
and that's the single-database glow-up β¨ now for the main eventβ¦
π Migrate a Cluster π
so this next bit shows you how to migrate a whole cluster. the first step is to add the required number of Valkey nodes to the existing cluster as replicas. once those new Valkey nodes have replicated the data, one Valkey replica gets promoted to be a brand new primary for each Redis primary. after the migration's done, the Redis nodes get removed from the cluster. iconic.
NOTE: you can also use data migration tools such as RIOT, RedisShake, and Redis-Migrate-Tool β but honestly that's beyond the scope of this document, so we're not getting into it. π
Requirements for this example:
- the Redis and Valkey cluster nodes are on the same network and can communicate with each other.
for this scenario, there's a Redis Cluster consisting of 3 primary and 3 replica nodes up and running. cute.
to perform the migration:
- use the
redis-clion one of the cluster nodes to check the current state of the cluster and make sure all the nodes are connected and active. in this cluster, there are three primary (master) and three replica (slave) nodes.
$ redis-cli -h 127.0.0.1 -p 6379 -c CLUSTER NODES
70beedebe43e422b275ee1a7bac0d3819dedca98 172.22.0.3:6379@16379 master - 0 1725450849000 1 connected 0-5460
8bbe836c59644f7395bbab09c6f8b36bc277e902 172.22.0.5:6379@16379 slave 58061fb2836bdb2f5a0973e1ccfd74a66166f329 0 1725450849510 3 connected
65061b94da5b481dc35c2df7dae13c233d4b3ad2 172.22.0.4:6379@16379 master - 0 1725450848000 2 connected 5461-10922
a242941d0e3edad27a954bc14ac3a3413f3040aa 172.22.0.7:6379@16379 slave 65061b94da5b481dc35c2df7dae13c233d4b3ad2 0 1725450849000 2 connected
3499854656f085ebb77b5b921389a91b7ae9d703 172.22.0.6:6379@16379 slave 70beedebe43e422b275ee1a7bac0d3819dedca98 0 1725450849829 1 connected
58061fb2836bdb2f5a0973e1ccfd74a66166f329 172.22.0.2:6379@16379 myself,master - 0 1725450846000 3 connected 10923-16383
- make a
valkey.confconfiguration file and specify these parameters. heads up: this config file is what enables clustering. the Valkey configuration file example provides a description of the various configuration arguments, iykyk.
# valkey.conf file
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
- start a Valkey instance with your custom configuration file. this command starts Valkey in Docker:
$ docker run -d -v myvalkey/conf:/usr/local/etc/valkey --name valkey-1 --net mynetwork valkey/valkey valkey-server /usr/local/etc/valkey/valkey.conf
where, bestie:
myvalkey/confis a local directory containing yourvalkey.confconfiguration file that is being mapped to the/usr/local/etc/valkeydirectory within the Docker Valkey container.valkey-1is the name of your container.mynetworkis the name of the network where Redis cluster is running.valkey/valkeyis the name of the Valkey image.
- retrieve the IP address of the Valkey instance β replacing
valkey-1with the name of your container, ofc.
$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' valkey-1
- add your new Valkey node to the Redis Cluster as a replica. replace the
redis-1,valkey-node-ip, andexisting-node-ipplaceholders with your actual values:
$ docker exec -it redis-1 bash
$ redis-cli --cluster add-node valkey-node-ip:6379 existing-node-ip:6379 --cluster-replica
- check the cluster status. the output of the
CLUSTER NODEScommand is described over incluster-nodes(3valkey).
$ redis-cli -c CLUSTER NODES
in the output you'll see the newly added node showing up as a replica (slave). for example, we added a Valkey node with the IP address 172.22.0.8:6379, and the cluster nodes list now has a brand new entry like this:
a98d5bac59672597b8509f24970e413002f896b6 172.22.0.8:6379@16379 slave 58061fb2836bdb2f5a0973e1ccfd74a66166f329 0 1725451086000 3 connected
- verify that your newly added Valkey node is recognized as a replica by running the
INFO REPLICATIONcommand. the output displays info about the node's primary. - start the
valkey-cliin your new Valkey container and enter the following command to promote it to primary.cluster-failover(3valkey)has the extra details if you want 'em.
docker exec -it valkey-container-name valkey-cli
valkey 127.0.0.1:6379> CLUSTER FAILOVER
OK
- use the
CLUSTER NODEScommand to display the cluster state and verify that your new Valkey node is now a new primary. main character energy, fr fr. - repeat steps 3-9 to add 2 more Valkey nodes and replace the Redis primary nodes.
- repeat steps 3-7 to add 3 Valkey replica nodes.
to add a replica to a specific primary, do the following:
- filter primary nodes. connect to any node in the Cluster and run this command, replacing
valkey-1with the name of your Valkey container:
$ docker exec -it valkey-1 bash
$ valkey-cli -c cluster nodes | grep master
70beedebe43e422b275ee1a7bac0d3819dedca98 172.22.0.3:6379@16379 master - 0 1725451135799 1 connected 0-5460
65061b94da5b481dc35c2df7dae13c233d4b3ad2 172.22.0.4:6379@16379 master - 0 1725451136000 2 connected 5461-10922
58061fb2836bdb2f5a0973e1ccfd74a66166f329 172.22.0.2:6379@16379 myself,master - 0 1725451136000 3 connected 10923-16383
NOTE: the node ID is the 40-character globally unique string that is generated when the node is created. in this example,70beedebe43e422b275ee1a7bac0d3819dedca98is the ID of the primary (master) node with the IP address172.22.0.3:6379. the ID of a node is required when adding a new Valkey replica to a specific primary in step b. π§
- add a new node to a specific primary, replacing
node-idwith your node ID:
$ valkey-cli --cluster add-node 172.22.0.10:6379 172.22.0.2:6379 --cluster-replica --cluster-master-id node-id
- remove Redis nodes:
redis-cli --cluster del-node 127.0.0.1:6379 node-id
the first argument is just a random node in the cluster, the second argument is the ID of the node you want to remove. simple as.
NOTE: if not for backward compatibility, the Valkey project no longer uses the words "master" and "slave". unfortunately, in the given commands these words are part of the protocol, so we'll be able to remove such occurrences only when this API is naturally deprecated. yeah. we know. π
and that's a wrap on the whole thing, babe π¦ this lil masterpiece is from version 9.0.0, dated 2025-10-21, and it lives at VALKEY-MIGRATION(7). go forth and migrate responsibly πβ¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms