DEV Community

Rijul Rajesh
Rijul Rajesh

Posted on

Redis Teleportation: Moving Data from Prod to Local in Minutes

Working with Redis in production can be a double-edged sword. It’s fast, powerful, and stores a lot of real-time data—but when you want to debug an issue locally or test with real data, things get tricky.

What Are We Trying to Do?

We want to export keys (and their values) from our production Redis instance and import them into our local Redis running on localhost:6379.

Tools We’ll Use

  • redis-cli: The default Redis command-line tool
  • ssh (optional): If your production Redis isn’t publicly accessible
  • A bit of scripting

Option 1: Dump and Restore Using RDB File

This method is great if you want a snapshot of your Redis database.

Step 1: Trigger Save on Prod

redis-cli -h your-prod-host -a your-password SAVE
Enter fullscreen mode Exit fullscreen mode

This forces Redis to write the current state to dump.rdb.

Step 2: Copy the RDB File to Your Local Machine

If you have SSH access:

scp user@your-prod-host:/var/lib/redis/dump.rdb ~/Downloads/
Enter fullscreen mode Exit fullscreen mode

Then move it to your local Redis directory (depends on your OS):

sudo mv ~/Downloads/dump.rdb /var/lib/redis/
sudo systemctl restart redis
Enter fullscreen mode Exit fullscreen mode

Warning: This will replace your existing local Redis data.


Option 2: Export Keys & Values with redis-cli

Step 1: Connect to Prod Redis and Export

redis-cli -h your-prod-host -a your-password --scan --pattern 'myprefix:*' |
while read key; do
  redis-cli -h your-prod-host -a your-password --raw DUMP "$key" > "dumps/$key.dump"
  redis-cli -h your-prod-host -a your-password TTL "$key" > "dumps/$key.ttl"
done
Enter fullscreen mode Exit fullscreen mode

You’ll get files like:

dumps/
  myprefix:user:1.dump
  myprefix:user:1.ttl
  ...
Enter fullscreen mode Exit fullscreen mode

Step 2: Import to Local Redis

for file in dumps/*.dump; do
  key=$(basename "$file" .dump)
  ttl=$(cat "dumps/$key.ttl")
  ttl=${ttl:-0}
  redis-cli RESTORE "$key" "$ttl" < "$file"
done
Enter fullscreen mode Exit fullscreen mode

your local Redis now has the keys.

Option 3: Use redis-dump and redis-load (Node.js Way)

If you're into Node.js, you can install redis-dump:

npm install -g redis-dump
Enter fullscreen mode Exit fullscreen mode

Dump from Prod

redis-dump -u redis://:your-password@your-prod-host:6379 > dump.json
Enter fullscreen mode Exit fullscreen mode

Load into Local

cat dump.json | redis-dump -u redis://localhost:6379 --load
Enter fullscreen mode Exit fullscreen mode

Wrapping up

Moving data from production to local Redis can be simple, but it requires a little care. Choose your method based on how much data you need and how sensitive it is. For full snapshots, go with the RDB approach. For selective migration, use the DUMP/RESTORE pattern or tools like redis-dump.

Have fun debugging and testing with real-world data—but always keep that security hat on.

If you're a software developer who enjoys exploring different technologies and techniques like this one, check out LiveAPI. It’s a super-convenient tool that lets you generate interactive API docs instantly.

LiveAPI helps you discover, understand and use APIs in large tech infrastructures with ease!

So, if you’re working with a codebase that lacks documentation, just use LiveAPI to generate it and save time!

You can instantly try it out here! 🚀

Top comments (0)