From 6f63e3ea1f49d2d262ed0649b1d4e37d52d476cd Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 23 Sep 2016 17:38:57 +0800 Subject: [PATCH] =?UTF-8?q?task=E4=BB=BB=E5=8A=A1=20mysql=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=A7=BB=E5=88=B0redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/mysql2redis.rake | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/tasks/mysql2redis.rake 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