BeITMemcached 示例Code
using System;
using System.Collections.Generic;
namespace BeIT.MemCached {
class Example {
[Serializable]
public class ab{
public string a;
public int b;
public abs absss;
}
[Serializable]
public class abs{
public string aaa="";
}
public static void Main(string[] args) {
//初始化服务器池,需要指定实例名及服务器组
//实例名主要是为了方便将应用程序需要缓存的数据进行分类,这样可以方便管理,提高性能
//例如可以session 存在一组memcached服务器,用户数据放在另一组服务器
//服务器是逻辑概念,IP+PORT即代表一个.
MemcachedClient.Setup("MyCache", new string[] { "10.0.5.115:11211" });
MemcachedClient.Setup("MyOtherCache", new string[] { "10.0.5.115:11212", "10.0.5.115:11213" });
Console.Out.WriteLine("Storing some items.");
cache2.Set("mystring", "The quick brown fox jumped over the lazy dog.");
cache2.Set("myarray", new string[] { "This is the first string.", "This is the second string." });
cache2.Set("myinteger", 4711);
cache2.Set("mydate", new DateTime(2008, 02, 23));
ab obj=new ab();
obj.a="sdfasdfasfdda中华人民共和国中华人民共和国 ";
obj.b=435;
obj.absss=new abs();
obj.absss.aaa="adfasdfasdfas";
cache2.Set("myobj",obj);
//Get a string
string str2 = cache2.Get("mystring") as string;
string[] array2 = cache2.Get("myarray") as string[];
object[] result2 = cache2.Get(new string[] { "myinteger", "mydate" });//一次取得多个键值