public BinaryCached(EndPoint[] servers, Encoding responseEncoding, ICompressProtocol compress, SocketSetting setting) : base(compress) { this.servers = servers; this.responseEncoding = responseEncoding; this.compress = compress; this.connectionPools = new ConnectionPool[servers.Length]; for (var i = 0; i < servers.Length; i++) { var connectionPool = new ConnectionPool(setting, servers[i], (set, end) => { var client = new Sockets.ClientSocket(set, end); client.Start().KeepAlive(set.KeepAlivePeriod); return(client.Connection); }); this.connectionPools[i] = connectionPool; } }
public BinaryCached(EndPoint[] servers, ICompressProtocol compress) : this(servers, Encoding.UTF8, compress) { }
public BinaryCached(EndPoint[] servers, Encoding responseEncoding, ICompressProtocol compress) : this(servers, responseEncoding, compress, new SocketSetting()) { }
/// <summary> /// 启动memcached支持 /// </summary> /// <param name="startup"></param> /// <param name="encoding"></param> /// <param name="memcachedType"></param> /// <param name="servers">服务列表</param> /// <param name="key">IoC容器中的key</param> /// <param name="compressProtocol"></param> /// <returns></returns> public static ApplicationStartup UseMemcached(this ApplicationStartup startup, MemcachedType memcachedType, Encoding encoding, string[] servers, string key = null, ICompressProtocol compressProtocol = null) { if (startup.Items.ContainsKey("UseMemcached" + key)) { return(startup); } var mem = memcachedType == MemcachedType.Text ? MemcachedClient.CreateTextCached(servers, encoding, compressProtocol ?? new GZipCompressProtocol() { }) : MemcachedClient.CreateBinaryCached(servers, encoding, compressProtocol ?? new GZipCompressProtocol() { }); startup.ServiceRegister.RegisterInstance(mem, typeof(ICaching), key); startup.Items["UseMemcached" + key] = "t"; return(startup); }
/// <summary> /// 创建二进制协议的client /// </summary> /// <param name="servers"></param> /// <param name="encoding"></param> /// <param name="setting"></param> /// <returns></returns> public static MemcachedClient CreateBinaryCached(string[] servers, Encoding encoding, ICompressProtocol compress, SocketSetting setting) { return(new BinaryCached(servers.Select(ta => Parse(ta)).ToArray(), encoding, compress, setting ?? new SocketSetting())); }
/// <summary> /// 创建二进制协议的client /// </summary> /// <param name="servers"></param> /// <param name="encoding"></param> /// <returns></returns> public static MemcachedClient CreateBinaryCached(string[] servers, Encoding encoding, ICompressProtocol compress) { return(CreateBinaryCached(servers, encoding, compress, new SocketSetting())); }
/// <summary> /// 创建二进制协议的client /// </summary> /// <param name="servers"></param> /// <returns></returns> public static MemcachedClient CreateBinaryCached(string[] servers, ICompressProtocol compress) { return(CreateBinaryCached(servers, Encoding.UTF8, compress)); }
protected MemcachedClient(ICompressProtocol compress) { this.compress = compress; }