Przeglądaj źródła

clear product user order redis

abiao 5 lat temu
rodzic
commit
7046bc370a
4 zmienionych plików z 37 dodań i 2 usunięć
  1. 11 0
      app/models/order.rb
  2. 10 1
      app/models/product.rb
  3. 11 1
      app/models/user.rb
  4. 5 0
      app/models/wx_user.rb

+ 11 - 0
app/models/order.rb

@@ -9,6 +9,8 @@ class Order < ActiveRecord::Base
     belongs_to :wx_user, :foreign_key => :wx_user_id
     has_many :order_details
     before_save :before_save
+    after_update :after_update
+
     def before_save
         if self.express_company.length>0
             express = ExpressCompany.where("express_company = ?", self.express_company).first
@@ -18,6 +20,15 @@ class Order < ActiveRecord::Base
         end
     end
 
+    def after_update
+        test_redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+        redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+
+        orderKey= format("order_model.GetOrderByOId:%s",self.order_id)
+        redis.del(orderKey)
+        test_redis.del(orderKey)
+
+    end
     STATUS_ENUM = [["未支付","unpay"],["已关闭","closed"],["待确认","unconfirmed"],["处理中","processing"],["已完成","complete"],["待收货","dispatch"],["已退款","refunded"]]
     TYPE_ENUM = [["普通",0],["秒杀",1],["店长",2]]
     EXP_ENUM =  []

+ 10 - 1
app/models/product.rb

@@ -7,7 +7,7 @@ class Product < ActiveRecord::Base
     attr_accessor :v_share_img,:get_size_enum,:gross_interest_rate
     after_find :get_size_enum
     after_create :after_create
-    #after_update :after_update
+    after_update :after_update
     before_save :before_save
     after_destroy :del_picture
 
@@ -40,6 +40,15 @@ class Product < ActiveRecord::Base
         end
     end
 
+    def after_update
+        test_redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+        redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+
+        prdKey= format("product_model.GetProductById:%d",self.id)
+        redis.del(prdKey)
+        test_redis.del(prdKey)
+
+    end
 
     TYPE_ENUM = [["直营","direct_sale"],["店铺专区","shop_sale"]]
     SIZE_ENUM =  []

+ 11 - 1
app/models/user.rb

@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
   has_paper_trail
   self.table_name = "users"
   belongs_to :parent_signup_channel, :foreign_key => :signup_channel_id
-
+  after_update :after_update
   after_create :after_create
   after_destroy :after_destroy
   attr_accessor :sub, :wx_user, :v_head, :getNickname, :getProvince
@@ -30,6 +30,16 @@ class User < ActiveRecord::Base
   #   end    
   # end
 
+  def after_update
+    test_redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+    redis = Redis.new(:host=>"r-wz9dtt12y12ns2b97gpd.redis.rds.aliyuncs.com",:db=>"0",:user=>"root",:password=>"Fohow123!@#")
+
+    userKey= format("user_model.GetKeyByUserId:%d",self.id)
+    redis.del(userKey)
+    test_redis.del(userKey)
+
+  end
+
   def after_create
     md5_trade_pwd = Digest::MD5.hexdigest(self.trade_pwd)
     self.trade_pwd = md5_trade_pwd

+ 5 - 0
app/models/wx_user.rb

@@ -31,6 +31,11 @@ class WxUser < ActiveRecord::Base
     userKey= format("userinfo_%d",self.id)
     redis.del(userKey)
     test_redis.del(userKey)
+
+    wxuserKey= format("user_model.GetWxUserById:%d",self.id)
+    redis.del(wxuserKey)
+    test_redis.del(wxuserKey)
+
   end
 
   def invite