Esempio n. 1
0
		private static IMemcachedClientConfiguration GetSection(string sectionName)
		{
			MemcachedClientSection section = (MemcachedClientSection)ConfigurationManager.GetSection(sectionName);
			if (section == null)
				throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");

			return section;
		}
Esempio n. 2
0
        /// <summary>
        /// Initializes a new MemcacedClient instance using the specified configuration section.
        /// This overload allows to create multiple MemcachedClients with different pool configurations.
        /// </summary>
        /// <param name="sectionName">The name of the configuration section to be used for configuring the behavior of the client.</param>
        public MemcachedClient(string sectionName)
        {
            MemcachedClientSection section = (MemcachedClientSection)ConfigurationManager.GetSection(sectionName);

            if (section == null)
            {
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            }

            this.pool = new ServerPool(section);
        }
        /// <summary>
        /// Gets the section.
        /// </summary>
        /// <returns>The client configuration.</returns>
        /// <exception cref="System.Configuration.ConfigurationErrorsException">
        /// If memcached client section was not found or there are no servers defined for memcached.
        /// </exception>
        private IMemcachedClientConfiguration GetSection()
        {
            string sectionName             = GetEnyimSectionName(this.Configuration.Name);
            MemcachedClientSection section = (MemcachedClientSection)ConfigurationManager.GetSection(sectionName);

            if (section == null)
            {
                throw new ConfigurationErrorsException("Client section " + sectionName + " is not found.");
            }

            // validate
            if (section.Servers.Count <= 0)
            {
                throw new ConfigurationErrorsException("There are no servers defined.");
            }

            return(section);
        }
Esempio n. 4
0
        /// <summary>
        /// 主入口
        /// </summary>
        /// <param name="args">参数</param>
        public static List <string> GetllKeys()
        {
            MemcachedClientSection config = ConfigurationManager.GetSection("enyim.com/memcached") as MemcachedClientSection;

            if (config != null && config.Servers.Count > 0)
            {
                var    server    = config.Servers.ToIPEndPointCollection()[0];
                string ipAddress = server.Address.ToString();
                var    port      = server.Port;

                var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(new IPEndPoint(IPAddress.Parse(ipAddress), port));
                var slabIdIter = QuerySlabId(socket);
                var keyIter    = QueryKeys(socket, slabIdIter);
                socket.Close();

                return(keyIter.ToList());
            }
            return(null);
        }
        /// <summary>
        /// Initializes a new MemcachedClient instance using the default configuration section (caching/whalinMemcached).
        /// </summary>
        public static MemcachedClient CreateClient()
        {
            MemcachedClientSection DefaultSettings = ConfigurationManager.GetSection("caching/whalinMemcached") as MemcachedClientSection;

            return(CreateClient(DefaultSettings));
        }