Skip to content

Instantly share code, notes, and snippets.

@hartleybrody
Last active February 20, 2025 15:35
Show Gist options
  • Select an option

  • Save hartleybrody/3d9f6a6f9ea43cbf2923ee2c6e65b140 to your computer and use it in GitHub Desktop.

Select an option

Save hartleybrody/3d9f6a6f9ea43cbf2923ee2c6e65b140 to your computer and use it in GitHub Desktop.

Revisions

  1. hartleybrody revised this gist Aug 23, 2022. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions backup-analyze-redis.sh
    Original file line number Diff line number Diff line change
    @@ -26,3 +26,21 @@ redis-server --dbfilename dump.rdb

    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


  2. hartleybrody revised this gist Aug 23, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions backup-analyze-redis.sh
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@

    redis-cli -u $PROD_REDIS_URL --rdb dump.rdb


    # 2. start your local redis-server using that
    # rdb snapshot file as an argument

    @@ -24,3 +25,4 @@ redis-server --dbfilename dump.rdb
    # source https://github.com/obukhov/redis-inventory

    docker run --rm dclg/redis-inventory inventory host.docker.internal:6379

  3. hartleybrody revised this gist Aug 23, 2022. No changes.
  4. hartleybrody renamed this gist Aug 23, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. hartleybrody created this gist Aug 23, 2022.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # 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