客户端连接实例
C#/.NET: EnyimMemcached
using System.Net;
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
namespace OCS.Memcached
{
public sealed class MemCached
{
private static MemcachedClient MemClient;
static readonly object padlock =
new object();
public static MemcachedClient
getInstance()
{
if (MemClient ==
null)
{
lock (padlock)
{
if (MemClient ==
null)
{
MemClientInit();
}
}
}
return MemClient;
}
static void MemClientInit()
{
MemcachedClientConfiguration memConfig =
new MemcachedClientConfiguration();
IPAddress newaddress =
IPAddress.Parse(Dns.GetHostEntry
(
"your_ocs_host").AddressList[
0].ToString());
IPEndPoint ipEndPoint =
new IPEndPoint(newaddress,
11211);
memConfig.Servers.Add(ipEndPoint);
memConfig.Protocol = MemcachedProtocol.Binary;
memConfig.Authentication.Type =
typeof(PlainTextAuthenticator);
memConfig.Authentication.Parameters[
"zone"] =
"";
memConfig.Authentication.Parameters[
"userName"] =
"username";
memConfig.Authentication.Parameters[
"password"] =
"password";
memConfig.SocketPool.MinPoolSize =
5;
memConfig.SocketPool.MaxPoolSize =
200;
MemClient=
new MemcachedClient(memConfig);
}
}
}
调用代码:
MemcachedClient MemClient =
MemCached.getInstance();
转载请注明原文地址: https://ju.6miu.com/read-26654.html