Skip to content

Instantly share code, notes, and snippets.

@edwardzhou
Created March 2, 2018 08:08
Show Gist options
  • Save edwardzhou/7c29cf864942d71c12a48ecb39ad432e to your computer and use it in GitHub Desktop.
Save edwardzhou/7c29cf864942d71c12a48ecb39ad432e to your computer and use it in GitHub Desktop.
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