public partial class _Default : System.Web.UI.Page
{
public static MemcachedClient mc = null;
protected void Page_Load(object sender, EventArgs e)
{
string id = "1";
String[] serverlist = { "127.0.0.1:11211" };
int[] weights ={ 3 };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);
pool.Nagle = false;
pool.Initialize();
mc = new MemcachedClient();
mc.EnableCompression = false; gbtopic obj = new gbtopic(id, 1, id+"合理咯电456thu");//gbtopic 是自定义的类
mc.Set(id, obj); Response.Write(mc.KeyExists(id).ToString());//这里显示true,键值“1”存在
}
}
[Serializable]
public class gbtopic
{
public string id;
public string title;
public int num;
public gbtopic(string id, int num, string title)
{
this.id = id;
this.num = num;
this.title = title;
}
}
====================================================
以上都没问题,一个asp.net网页创建类,存入Memcached,可以得到。但是我新建一个命令行程序class Program
{
public static MemcachedClient mc = null;
static void Main(string[] args)
{
string id = "1";
String[] serverlist = { "127.0.0.1:11211" };
int[] weights ={ 3 };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);
pool.Nagle = false; pool.Initialize(); mc = new MemcachedClient(); mc.EnableCompression = false; Console.WriteLine(mc.KeyExists(id).ToString())//这里显示false,为什么都是key为“1”这里读不到
Console.ReadLine();
}
}
我又做了试验,把那个asp.net网页 的mc.Set(id, obj);
改成mc.Set(id, "strobj");//只存放一个string
再运行命令行程序,就显示true了。问题总结:
存放类的实例,本工程内可以正常读取,另一个程序读不到。但存在简单变量string,int等,多个程序都能读到。
显示false的期间我用telnet 127.0.0.1 11211
get 1
试过,key为1的确实存在,但另一个程序mc.KeyExists(id)就是显示false,为什么?
{
public static MemcachedClient mc = null;
protected void Page_Load(object sender, EventArgs e)
{
string id = "1";
String[] serverlist = { "127.0.0.1:11211" };
int[] weights ={ 3 };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);
pool.Nagle = false;
pool.Initialize();
mc = new MemcachedClient();
mc.EnableCompression = false; gbtopic obj = new gbtopic(id, 1, id+"合理咯电456thu");//gbtopic 是自定义的类
mc.Set(id, obj); Response.Write(mc.KeyExists(id).ToString());//这里显示true,键值“1”存在
}
}
[Serializable]
public class gbtopic
{
public string id;
public string title;
public int num;
public gbtopic(string id, int num, string title)
{
this.id = id;
this.num = num;
this.title = title;
}
}
====================================================
以上都没问题,一个asp.net网页创建类,存入Memcached,可以得到。但是我新建一个命令行程序class Program
{
public static MemcachedClient mc = null;
static void Main(string[] args)
{
string id = "1";
String[] serverlist = { "127.0.0.1:11211" };
int[] weights ={ 3 };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);
pool.Nagle = false; pool.Initialize(); mc = new MemcachedClient(); mc.EnableCompression = false; Console.WriteLine(mc.KeyExists(id).ToString())//这里显示false,为什么都是key为“1”这里读不到
Console.ReadLine();
}
}
我又做了试验,把那个asp.net网页 的mc.Set(id, obj);
改成mc.Set(id, "strobj");//只存放一个string
再运行命令行程序,就显示true了。问题总结:
存放类的实例,本工程内可以正常读取,另一个程序读不到。但存在简单变量string,int等,多个程序都能读到。
显示false的期间我用telnet 127.0.0.1 11211
get 1
试过,key为1的确实存在,但另一个程序mc.KeyExists(id)就是显示false,为什么?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货