Created
March 2, 2018 08:08
-
-
Save edwardzhou/7c29cf864942d71c12a48ecb39ad432e to your computer and use it in GitHub Desktop.
This file contains 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
KEY_PREFIX = 'cn:campaign:201838:'.freeze | |
def import_telephones(filename, overwrite = false) | |
IO.readlines(filename).each do |line| | |
telephone = line.strip | |
next if telephone.blank? | |
key = "#{KEY_PREFIX}#{telephone}" | |
if overwrite || $redis.get(key).nil? | |
puts "import #{telephone}" | |
$redis.set key, 0 | |
else | |
puts "skip #{telephone}" | |
end | |
end | |
nil | |
end | |
def export_telephones(filename) | |
File.open(filename, "w") do |file| | |
$redis.keys("#{KEY_PREFIX}*").each do |key| | |
customer_id = $redis.get(key) | |
telephone = key.sub("#{KEY_PREFIX}", '') | |
file.puts "#{telephone}, #{customer_id}" | |
end | |
end | |
nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment