redis dump key to file in windows then restore it to another redis
To dump a specific key from a Redis database to a file on Windows and then restore it to another Redis instance, you can follow these steps:
Open Command Prompt: Open the Command Prompt on your Windows machine.
Use redis-cli
to Dump the Key: Use the redis-cli
tool to export the key. Replace your_key
with the key you want to dump, and source_redis_host
and source_redis_port
with your source Redis instance details.
redis-cli -h source_redis_host -p source_redis_port --raw DUMP your_key > your_key.dump
This command will create a file named your_key.dump
containing the serialized value of the key.
Read the Dump File: You need to read the contents of the dump file into a variable. You can do this using PowerShell or a similar tool.
Use redis-cli
to Restore the Key: Use the redis-cli
tool to restore the key to the target Redis instance. Replace target_redis_host
and target_redis_port
with your target Redis instance details.
$data = Get-Content -Raw -Path .\your_key.dump
redis-cli -h target_redis_host -p target_redis_port RESTORE your_key 0 $data
0
is the TTL (time to live) in milliseconds. If you want the key to expire, replace 0
with the desired TTL in milliseconds.DUMP
and RESTORE
commands work with all Redis data types.By following these steps, you should be able to successfully dump a key from one Redis instance and restore it to another on a Windows machine.