using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Test.Common
{
public class MemcacheHelper
{
private static readonly MemcachedClient mc = null; static MemcacheHelper()
{
//最好放在配置文件中
string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" }; //初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist); pool.InitConnections = ;
pool.MinConnections = ;
pool.MaxConnections = ; pool.SocketConnectTimeout = ;
pool.SocketTimeout = ; pool.MaintenanceSleep = ;
pool.Failover = true; pool.Nagle = false;
pool.Initialize(); // 获得客户端实例
mc = new MemcachedClient();
mc.EnableCompression = false;
}
/// <summary>
/// 存储数据
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool Set(string key,object value)
{
return mc.Set(key, value);
}
public static bool Set(string key, object value,DateTime time)
{
return mc.Set(key, value,time);
}
/// <summary>
/// 获取数据
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object Get(string key)
{
return mc.Get(key);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool Delete(string key)
{
if (mc.KeyExists(key))
{
return mc.Delete(key); }
return false; }
}
}

最新文章

  1. 基于jquery的消息提示框toastr.js
  2. TF Boys (TensorFlow Boys ) 养成记(二)
  3. C#中Dictionary,Hashtable,List的比较及分析
  4. win7下安装MYSQL报错:&quot;MYSQL 服务无法启动&quot;的3534问题
  5. 什么是锚点(AnchorPoint)
  6. 关于Linux vi命令 vi命令一览表
  7. window scipy install
  8. lambda -- Filter Java Stream to 1 and only 1 element
  9. Html.RenderAction简单用法
  10. 用POP动画引擎实现衰减动画(POPDecayAnimation)
  11. .net core 开发短网址平台的思路
  12. Java学习之封装
  13. [self init]
  14. #WEB安全基础 : HTML/CSS | 文章索引
  15. Repository HDU - 2846 字典树
  16. cdh5.15集群添加spark2.3服务(parcels安装)
  17. 8--Python入门--函数
  18. Elasticsearch增删改查
  19. JQ 弹出层全屏
  20. 20170727xlVBA根据数据表和模板工作簿生成个人明细表工作簿

热门文章

  1. LeetCode——8. String to Integer (atoi)
  2. Windows 使用windump进行循环抓包
  3. P2837晚餐队列安排
  4. Ansible基础入门
  5. [转][C#]降级.net 源码4.5
  6. mysql锁文章
  7. MySQL学习----多版本并发mvcc
  8. [UE4]GameInstance初始化
  9. crm 任务 状态
  10. mysql连接状态