Skip to content

Instantly share code, notes, and snippets.

@benweint
Last active December 18, 2015 01:28
Show Gist options
  • Save benweint/5703880 to your computer and use it in GitHub Desktop.
Save benweint/5703880 to your computer and use it in GitHub Desktop.
pdx.rb Redis presentation notes
# Redis memory dump tool
https://github.com/sripathikrishnan/redis-rdb-tools
# Generate dump csv
rdb -c memory dump.rdb >dump.csv
# Filter out unique IDs from Redis key names
time cat dump.csv | ruby -pe '$_.gsub! /:\d+:/, ":"' >keys.csv
# ... or in Perl
time cat dump.csv | perl -pe 's/:\d+:/:/g' >keys.csv
# CSVKit
http://csvkit.readthedocs.org/en/latest/
# Import CSV file into a sqlite database using csvkit
csvsql -i sqlite keys.csv | sqlite3 keys.db
sqlite3 keys.db
.schema
.mode csv
.import ./keys.csv keys
# Analyze in sqlite
SELECT key,ROUND(AVG(num_elements)),SUM(size_in_bytes)/1024/1024 FROM keys GROUP BY key;
# Write a script to truncate
bundle exec rails console
User.find_each do |user|
zset = "recommendable:users:#{user.id}:recommended_wiggles"
Recommendable.redis.zremrangebyrank(zset, 0, -101)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment