Forráskód Böngészése

redis连接测试

abiao 5 éve
szülő
commit
a7c0e69ce6
1 módosított fájl, 10 hozzáadás és 0 törlés
  1. 10 0
      app/models/wx_user.rb

+ 10 - 0
app/models/wx_user.rb

@@ -1,5 +1,6 @@
 # encoding:utf-8
 #微信用户表
+require 'redis'
 class WxUser < ActiveRecord::Base
   has_paper_trail
   self.table_name = "wx_users"
@@ -9,6 +10,7 @@ class WxUser < ActiveRecord::Base
   validates_presence_of :nickname, :unionid
   #belongs_to :channel_qrcode
   attr_accessor :invite, :v_head, :intro_user
+  after_update :after_update
 
   SEX_ENUM= [["未知","0"], ["男性","1"], ["女性", "2"]]
   RANK_ENUM= [["普通会员","0"], ["群主","1"], ["店长", "2"]]
@@ -19,6 +21,14 @@ class WxUser < ActiveRecord::Base
 
   after_destroy :after_destroy
 
+  def after_update
+    test_redis = Redis.new(url: "redis://root:Fohow123!@#"+"@r-wz9nmvnbdsek8yl476pd.redis.rds.aliyuncs.com:6379/0")
+    redis = Redis.new(url: "redis://root:Fohow123!@#"+"@r-wz9nmvnbdsek8yl476pd.redis.rds.aliyuncs.com:6379/2")
+    userKey= format("userinfo_%d",self.id)
+    redis.del(userKey)
+    test_redis.del(userKey)
+  end
+
   def invite
     wu = WxUser.where("id = ?", invite_id).first
     if !wu.blank?