Last active
December 28, 2015 10:49
-
-
Save pjanuario/7489450 to your computer and use it in GitHub Desktop.
This script migrates redis keys namespaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'redis' | |
| module RedisMigrator | |
| def self.run | |
| from = "production:" | |
| to = "development:" | |
| start = Time.now | |
| r = Redis.new | |
| k = 0 | |
| keys = r.keys("#{from}*") | |
| puts "Start migrating #{keys.size}..." | |
| keys.each do |key| | |
| s_key = key.sub(from, to) | |
| r.rename(key, s_key) | |
| k += 1 | |
| puts "#{k} keys renamed..." if (k % 100) == 0 | |
| end | |
| puts "Migrated #{k} keys from '#{from}' to '#{to}'... " | |
| puts "Took #{Time.now - start}s" | |
| end | |
| def self.run_clean_keys_from | |
| from = "launch:" | |
| start = Time.now | |
| r = Redis.new | |
| k = 0 | |
| keys = r.keys("#{from}*") | |
| puts "Start deleting #{keys.size}..." | |
| keys.each do |key| | |
| r.del key | |
| k += 1 | |
| puts "#{k} keys deleted..." if (k % 100) == 0 | |
| end | |
| puts "Deleteted #{k} keys from '#{from}... " | |
| puts "Took #{Time.now - start}s" | |
| end | |
| end |
Por que isso não é uma rake?
Concordando com @agravem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
move key to db 2 after renaming...