Example #1
0
        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;
            }
        }
Example #2
0
 public BinaryCached(EndPoint[] servers, ICompressProtocol compress) : this(servers, Encoding.UTF8, compress)
 {
 }
Example #3
0
 public BinaryCached(EndPoint[] servers, Encoding responseEncoding, ICompressProtocol compress) : this(servers, responseEncoding, compress, new SocketSetting())
 {
 }
Example #4
0
        /// <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);
        }
Example #5
0
 /// <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()));
 }
Example #6
0
 /// <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()));
 }
Example #7
0
 /// <summary>
 /// 创建二进制协议的client
 /// </summary>
 /// <param name="servers"></param>
 /// <returns></returns>
 public static MemcachedClient CreateBinaryCached(string[] servers, ICompressProtocol compress)
 {
     return(CreateBinaryCached(servers, Encoding.UTF8, compress));
 }
Example #8
0
 protected MemcachedClient(ICompressProtocol compress)
 {
     this.compress = compress;
 }