diff --git a/lib/tasks/mysql2redis.rake b/lib/tasks/mysql2redis.rake new file mode 100644 index 000000000..861411bb9 --- /dev/null +++ b/lib/tasks/mysql2redis.rake @@ -0,0 +1,31 @@ +#coding=utf-8 + +namespace :mysql2redis do + + task :mysql2redis=> :environment do + puts "start mysql2redis." + + mysqlTableName = ARGV[1] + + puts mysqlTableName + + begin + className = mysqlTableName.classify.constantize + puts "class ="+className.to_s + puts className.count + count = 0 + className.where("").find_each do|tmp| + key = mysqlTableName+":"+tmp.id.to_s + tmp.attributes.each do |k,v| + $redis.hset(key,k,v) + end + count = count + 1 + end + puts "count = "+count.to_s + rescue + puts "this table is not exist!" + end + + puts "end mysql2redis." + end +end \ No newline at end of file