string[] servers = { "127.0.0.1:11211", "127.0.0.1:11211" };
SockIOPool pool;
MemcachedClient mc;
public Memcached()
{
//初始化池
pool = SockIOPool.GetInstance();
pool.SetServers(servers);
pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 1000;
pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;
pool.MaintenanceSleep = 30;
pool.Failover = true;
pool.Nagle = false;
pool.Initialize();
mc = new MemcachedClient();
mc.EnableCompression = false;
}
public void Remove(string key)
{
mc.Delete(key);
}
public bool Set(string key, object value)
{
return mc.Set(key, value);
}
public bool Set(string key, object value, int minute)
{
return mc.Set(key, value, DateTime.Now.AddMinutes(minute));
}
public Hashtable Stats()
{
return mc.Stats();
}
public object Get(string key)
{
return mc.Get(key);
}
public bool ContainsKey(string key)
{
return mc.KeyExists(key);
}
VB.NET
代码
Dim servers() As String = {"127.0.0.1:11211", "127.0.0.1:11211"}
Dim pool As SockIOPool
Dim mc As New MemcachedClient
Public Function Memcached() As Integer
'初始化池
pool = SockIOPool.GetInstance()
pool.SetServers(servers)
pool.InitConnections = 3
pool.MinConnections = 3
pool.MaxConnections = 1000
pool.SocketConnectTimeout = 1000
pool.SocketTimeout = 3000
pool.MaintenanceSleep = 30
pool.Failover = True
pool.Nagle = False
pool.Initialize()
mc = New MemcachedClient()
mc.EnableCompression = False
End Function
Public Sub RemoveMEM(ByVal key As String)
mc.Delete(key)
End Sub
Public Function SetMEM(ByVal key As String, ByVal value As Object) As Boolean
Return mc.Set(key, value)
End Function
Public Function SetMEM(ByVal key As String, ByVal value As Object, ByVal minute As Integer) As Boolean
Return mc.Set(key, value, DateTime.Now.AddMinutes(minute))
End Function
Public Function StatsMEM() As Hashtable
Return mc.Stats()
End Function
Public Function GetMEM(ByVal key As String) As Object
Return mc.Get(key)
End Function
Public Function ContainsKey(ByVal key As String) As Boolean
Return mc.KeyExists(key)
End Function