.net中Memcached的應用實例

.NET中使用Memcached的相關資源整理:

http://www.cnblogs.com/dudu/archive/2009/07/19/1526407.html

.NET中Memcached的一個應用實例:

//引用:
PulcFunctions.TestMemCached(strMobile, strMsg);
公共方法:
 public static bool TestMemCached(string Mobile ,string Msg)
  {
      bool Count = false;
      bool Content = false;
      string countKey = "Count_MemCached_" + strMobile;
      string ContKey = "Cont_MemCached_" + PulcFunctions.MD5Encode(Mobile + Msg);
      TimeSpan RemainTime = DateTime.Today.AddDays(1) - DateTime.Now;
      //判斷手機號是否重複三次
      if (MemcachedHelper.KeyExists(countKey))
      {
          int countKeyNumber = (int)MemcachedHelper.Get(countKey);
          if (countKeyNumber < 3)
          {
              MemcachedHelper.Set(countKey, ++countKeyNumber, RemainTime);
              Count = true;
          }
      }
      else
      {
          MemcachedHelper.Set(countKey, 1, RemainTime);
          Count = true;
      }
      //判斷內容是否重複
      if (!MemcachedHelper.KeyExists(ContKey))
      {
          MemcachedHelper.Set(ContKey, 1, RemainTime);
          Content = true;
      }
      return Content && Count;
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章