Skip to content

Instantly share code, notes, and snippets.

@hartleybrody
Last active August 23, 2022 16:31
Show Gist options
  • Save hartleybrody/3d9f6a6f9ea43cbf2923ee2c6e65b140 to your computer and use it in GitHub Desktop.
Save hartleybrody/3d9f6a6f9ea43cbf2923ee2c6e65b140 to your computer and use it in GitHub Desktop.
backup a production redis URL to your local redis server (and analyze key usage)
# 1. download a copy of prod db to localhost
# connect to remote redis database and
# download a snapshot of the entire database
# to a local file on your filesystem
# via https://stackoverflow.com/a/61365048/625840
# docs https://redis.io/docs/manual/cli/#remote-backups-of-rdb-files
redis-cli -u $PROD_REDIS_URL --rdb dump.rdb
# 2. start your local redis-server using that
# rdb snapshot file as an argument
# via https://stackoverflow.com/a/71282587/625840
redis-server --dbfilename dump.rdb
# 3. BONUS! Analyze your local copy of the
# production redis database using redis-inventory
# via https://dclg.net/posts/2021-08-16---Redis-inventory/redis-inventory
# source https://github.com/obukhov/redis-inventory
docker run --rm dclg/redis-inventory inventory host.docker.internal:6379
# 4. Reclaim memory from deleted keys
# if you've deleted a bunch of keys but haven't seen
# memory usage drop back down yet, you can manually run
# `memory purge` at the redis-cli and give it ~1hr
# note that, per the docs, this only works if the
# allocator is set to `jemalloc`
# docs https://redis.io/commands/memory-purge/
redis-cli -u $PROD_REDIS_URL
> INFO memory
...
mem_allocator:jemalloc-5.1.0
...
> MEMORY PURGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment