.net memcache
2024-10-19 11:57:18
非常感谢csdn及冷月宫主让我很快学会了.net操作 memcache 文章转自:http://download.csdn.net/detail/e_wsq/4358982
C#存取Memcache的示例 1 将Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll 等放到bin目录 2 引用Memcached.ClientLibrary.dll
string[] serverlist = { "127.0.0.1:11211", "90.0.12.120: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(); // 获得客户端实例
MemcachedClient mc = new MemcachedClient();
mc.EnableCompression = false; Console.WriteLine("------------测 试-----------");
mc.Set("test1", "this is test"); //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test" if (mc.KeyExists("test")) //测试缓存存在key为test的项目
{
Console.WriteLine("KEY为test的值正确写入");
Console.WriteLine("test的值是:"+mc.Get("test").ToString()); //在缓存中获取key为test的项目
}
else
{
Console.WriteLine("test not Exists");
} // Console.ReadLine();
var tt = mc.Get("test");
//mc.Delete("test"); //移除缓存中key为test的项目 if (mc.KeyExists("test"))
{
Console.WriteLine("test is Exists");
Console.WriteLine(mc.Get("test").ToString());
}
else
{
Console.WriteLine("值已删除");
}
//Console.ReadLine(); SockIOPool.GetInstance().Shutdown(); //关闭池, 关闭sockets
最新文章
- 第一次打开Lightroom时的基本设置
- MySQL 安装和启动服务,“本地计算机 上的 MySQL 服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止。”
- [Word]将word文件中的软回车符[↓]替换为硬回车符
- 【HDU4419 Colourful Rectangle】 线段树面积并
- rpm安装rpm-package报错:Header signature NOKEY 和 error: Failed dependencies:
- 如何在OpenWRT环境下做开发
- JSTL和select标签的组合使用
- JDBC连接SQLServer的几种方式
- 局部敏感哈希(Locality-Sensitive Hashing, LSH)方法介绍
- BM算法详解
- 掌握好这23个Linux命令常用项
- Javascript时间戳和日期时间的相互转换
- 关于python format()用法详解
- IntelliJ IDEA 2017版 spring-boot2.0.2 自动配置Condition
- 手把手教你封装 Vue 组件并使用 NPM 发布
- 为什么说 LINQ 要胜过 SQL
- CSS相对定位|绝对定位(五)之z-index篇——张鑫旭
- 【BZOJ】1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏(floyd)
- Linux buffer and cache
- RadioGroup多行显示