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