COnfiguration class
Наследование: IMemcachedClientConfiguration
Пример #1
0
		public void TestThrottlingFailurePolicy()
		{
			var config = new MemcachedClientConfiguration();
			config.AddServer("nonexisting.enyim.com:2244");

			config.SocketPool.FailurePolicyFactory = new ThrottlingFailurePolicyFactory(4, TimeSpan.FromMilliseconds(2000));
			config.SocketPool.ConnectionTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.MinPoolSize = 1;
			config.SocketPool.MaxPoolSize = 1;

			var client = new MemcachedClient(config);
			var canFail = false;
			var didFail = false;

			client.NodeFailed += node =>
			{
				Assert.IsTrue(canFail, "canfail");

				didFail = true;
			};

			Assert.IsNull(client.Get("a"), "Get should have failed. 1");
			Assert.IsNull(client.Get("a"), "Get should have failed. 2");

			canFail = true;
			Thread.Sleep(2000);

			Assert.IsNull(client.Get("a"), "Get should have failed. 3");
			Assert.IsNull(client.Get("a"), "Get should have failed. 4");
			Assert.IsNull(client.Get("a"), "Get should have failed. 5");
			Assert.IsNull(client.Get("a"), "Get should have failed. 6");

			Assert.IsTrue(didFail, "didfail");
		}
        public override void Initialize()
        {
            lock (locker) {
                // Check we don't already have a client
                if (client != null) return;

                // Set up configuration
                config = new MemcachedClientConfiguration();

                var ts = new TimeSpan(0,0,30);

                config.SocketPool.ConnectionTimeout = ts;
                config.SocketPool.ReceiveTimeout = ts;
                config.SocketPool.DeadTimeout = ts;
                //config.SocketPool.QueueTimeout = ys;
                config.SocketPool.MinPoolSize = 1;
                config.SocketPool.MaxPoolSize = 10;

                foreach(string server in cache_servers) config.AddServer(server);

                config.Protocol = MemcachedProtocol.Text;

                // Create client
                client = new MemcachedClient(config);
            }
        }
Пример #3
0
        public void TestThem(List<string> servers)
        {
            var mbc = new MemcachedClientConfiguration();
            foreach (var server in servers)
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(server), 11211);
                mbc.Servers.Add(endPoint);
            }

            _couchbaseClient = new MemcachedClient(mbc);

            _couchbaseClient.Store(StoreMode.Set, Key, Value);
            Debug.Assert((string)_couchbaseClient.Get(Key) == Value);

            List<Thread> workers = new List<Thread>();

            for (int s = 0; s < NumThreads; s++)
            {
                Thread workerThread = new Thread(Run);
                workerThread.Start();
                workers.Add(workerThread);
            }

            foreach (var thread in workers)
            {
                while (thread.IsAlive)
                {
                    Thread.Sleep(1);
                }

                thread.Join();
            }
        }
Пример #4
0
 public void Setup()
 {
     var configuration = new MemcachedClientConfiguration();
     configuration.AddServer("127.0.0.1", PortNumber);
     _memcachedEntityTagStore = new MemcachedEntityTagStore(configuration);
     _memcachedEntityTagStore.Clear();
 }
Пример #5
0
        public static MemcachedClient CreateClient(ITranscoder transcoder)
        {
            var config = new MemcachedClientConfiguration() { Protocol = MemcachedProtocol.Binary, Transcoder = transcoder };
            config.Servers.Add(new System.Net.IPEndPoint(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), 11211));

            return new MemcachedClient(config);
        }
Пример #6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Width = 550;
            try
            {
                mcache_config = new MemcachedClientConfiguration();
                mcache_config.Servers.Add(new IPEndPoint(IPAddress.Parse(localhost), mcache_port));
                mcache_config.Protocol = MemcachedProtocol.Text;
                mcache_client = new Enyim.Caching.MemcachedClient(mcache_config);

                DataBase_0.Open();
                DataBase_1.Open();
                DataBase_2.Open();
                DataBase_3.Open();
                DataBase_4.Open();
                DataBase_info.Open();
            }
            catch (SqlException)
            {
                MessageBox.Show(
                    "Connection failed. DataBases states:\n" +
                    "\nDataBase #1: " + DataBase_0.State.ToString() +
                    "\nDataBase #2: " + DataBase_1.State.ToString() +
                    "\nDataBase #3: " + DataBase_2.State.ToString() +
                    "\nDataBase #4: " + DataBase_3.State.ToString() +
                    "\nDataBase #5: " + DataBase_4.State.ToString() +
                    "\nDataBase info: " + DataBase_info.State.ToString()
                );
            }
            catch (Exception error) { MessageBox.Show("MainForm_Load: " + error.Message); }
        }
        public void SetUp()
        {
            var config = new MemcachedClientConfiguration();
            config.AddServer("127.0.0.1", 11211);

            _Client = new MemcachedClient(config);
        }
        public CouchbaseRestConfiguration(string bucket, string username, string password, params Uri[] couchbaseServers)
        {
            if (couchbaseServers == null) throw new ArgumentNullException("couchbaseServers");
            if (bucket == null) throw new ArgumentNullException("bucket");
            if (username == null) throw new ArgumentNullException("username");
            if (password == null) throw new ArgumentNullException("password");

            CouchbaseServers =  new List<Uri>(couchbaseServers);
            Bucket = bucket;
            Username = username;
            Password = password;
            ClientId = "couchbase_net_rest";

            RequestTimeout = TimeSpan.FromMilliseconds(500);

            log4net.Config.XmlConfigurator.Configure();

            Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            MemcachedConfiguration = new MemcachedClientConfiguration();
            MemcachedConfiguration.Protocol = MemcachedProtocol.Binary;
            MemcachedConfiguration.Authentication.Type = typeof(PlainTextAuthenticator);
            MemcachedConfiguration.Authentication.Parameters.Add("zone", bucket);
            MemcachedConfiguration.Authentication.Parameters.Add("userName", username);
            MemcachedConfiguration.Authentication.Parameters.Add("password", password);
        }
Пример #9
0
 private void InitializeMemcachedClient()
 {
     var config = new MemcachedClientConfiguration();
     var address = ConfigurationManager.AppSettings.Get("MemcachedAddress");
     var port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MemcachedPort"));
     config.AddServer(address, port);
     Cache.Initialize(config);
 }
Пример #10
0
 public MemcacheCacheProvider(string cacheName, string[] cacheServers)
     : base()
 {
     locker = new object();
     cache_name = cacheName;
     cache_servers = cacheServers;
     config = null;
     client = null;
 }
Пример #11
0
        static MemcachedClientConfiguration GetConfig()
        {
            const string server = "192.168.0.8";
            const int port = 11211;

            var config = new MemcachedClientConfiguration();
            config.AddServer(server, port);
            return config;
        }
        public IMemcachedClient Create(IMemcachedSettings memcachedSettings)
        {
            var mcConfig = new MemcachedClientConfiguration();

            foreach (var server in memcachedSettings.Server)
                mcConfig.AddServer(server.Item1, server.Item2);

            mcConfig.Protocol = MemcachedProtocol.Text;
            return new MemcachedClient(mcConfig);
        }
 static MemcachedSessionStateStoreProvider()
 {
     SessionKey = ConfigurationManager.AppSettings["MemcachedSessionKey"] ?? "MemcachedSession";
     MemcachedClient = new Lazy<MemcachedClient>(() =>
     {
         var configuration = new MemcachedClientConfiguration();
         configuration.AddServer(ConfigurationManager.AppSettings["MemcachedServerAddress"]);
         configuration.Protocol = MemcachedProtocol.Binary;
         return new MemcachedClient(configuration);
     });
 }
        public MemcachedClientConfiguration Build()
        {
            var config = new MemcachedClientConfiguration();
            foreach (IPEndPoint ep in eps)
            {
                config.Servers.Add(ep);
            }

            config.NodeLocator = locator ?? typeof(NodeLocatorNotifierDecorator<DefaultNodeLocator>);

            return config;
        }
        private static MemcachedClientConfiguration GetMemcachedClientConfiguration()
        {
            //每次都要新建
            var config = new MemcachedClientConfiguration();
            foreach (var server in _serverlist)
            {
                config.Servers.Add(new IPEndPoint(IPAddress.Parse(server.Key), server.Value));
            }
            config.Protocol = MemcachedProtocol.Binary;

            return config;
        }
Пример #16
0
        /// <summary>
        /// Contructor
        /// </summary>
        public MemCacheHelper()
        {
            MemcachedClientConfiguration config = new MemcachedClientConfiguration();
            config.Servers.Add(GetIPEndPointFromHostName(MEMCACHE_HOST, MEMCACHE_PORT));
            config.Protocol = MemcachedProtocol.Binary;
            config.Authentication.Type = typeof(PlainTextAuthenticator);
            config.Authentication.Parameters["userName"] = "******";
            config.Authentication.Parameters["password"] = "******";
            config.Authentication.Parameters["zone"] = "";

            _mc = new MemcachedClient(config);
        }
Пример #17
0
		public void TestIfCalled()
		{
			var config = new MemcachedClientConfiguration();
			config.AddServer("nonexisting.enyim.com:2244");

			config.SocketPool.FailurePolicyFactory = new FakePolicy();
			config.SocketPool.ConnectionTimeout = TimeSpan.FromSeconds(4);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromSeconds(6);

			var client = new MemcachedClient(config);

			Assert.IsNull(client.Get("a"), "Get should have failed.");
		}
Пример #18
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            // or just initialize the client from code
            var nscc = new MembaseClientConfiguration();

            nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
            nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default"));
            //nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default"));
            nscc.Credentials = new NetworkCredential("A", "11111111");
            nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory();
            //nscc.BucketPassword = "******";

            ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_A_"));
            ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content"), "TesT_B_"));

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_"));

            Console.ReadLine();

            return;

            var mcc = new MemcachedClientConfiguration();
            mcc.AddServer("192.168.2.200:11211");
            mcc.AddServer("192.168.2.202:11211");

            mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            StressTest(new MemcachedClient(mcc), "TesT_");

            return;

            var nc = new MembaseClient(nscc, "content");

            var stats1 = nc.Stats("slabs");
            foreach (var kvp in stats1.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);

            var nc2 = new MembaseClient(nscc, "content");

            var stats2 = nc2.Stats();
            foreach (var kvp in stats2.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
        }
        public MemcachedClient GetClient() {
            // caches the ignored urls to prevent a query to the settings
            var servers = _cacheManager.Get("MemcachedSettingsPart.Servers",
                context => {
                    context.Monitor(_signals.When(MemcachedSettingsPart.CacheKey));

                    var part = _service.Value.GetSiteSettings().As<MemcachedSettingsPart>();

                    // initializes the client to notify it has to be constructed again
                    lock (_synLock) {
                        if (_client != null) {
                            _client.Dispose();
                        }
                        _client = null;
                    }
                    
                    return part.Servers;
                }
            );

            if (_client == null  && !String.IsNullOrEmpty(servers)) {
                var configuration = new MemcachedClientConfiguration();
                using (var urlReader = new StringReader(servers)) {
                    string server;
                    // ignore empty lines and comments (#)
                    while (null != (server = urlReader.ReadLine())) {
                        if (String.IsNullOrWhiteSpace(server) || server.Trim().StartsWith("#")) {
                            continue;
                        }

                        var values = server.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        int port = 11211;

                        if (values.Length == 2) {
                            Int32.TryParse(values[1], out port);
                        }

                        if (values.Length > 0) {
                            configuration.AddServer(values[0], port);
                        }
                    }

                    lock (_synLock) {
                        _client = new MemcachedClient(configuration);
                    }
                }

            }

            return _client;
        }
 public MemcacheCL()
 {
     MemcachedClientConfiguration config = new MemcachedClientConfiguration();
     config.AddServer(Settings.ipAddress, Settings.port);
     config.Protocol = MemcachedProtocol.Binary;
     try
     {
         _mc = new MemcachedClient(config);
     }
     catch (MemcachedClientException e)
     {
         Logger.Log(string.Format("Could not connect to the memcached daemon! Reason: {0}",e), Logger.LogType.Error, typeof(MemcacheCL));
     }
 }
Пример #21
0
        public void Constructor()
        {
            // set service cache provider from app.config
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache());

            // set service cache provider from a IMemcachedClientConfiguration
            var configuration = new MemcachedClientConfiguration();
            configuration.AddServer("serveraddress", 11211);
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache(configuration));

            // set service cache provider from an existing MemcachedClient
            var memcachedClient = new MemcachedClient();
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache(memcachedClient));
        }
Пример #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                mcache_config = new MemcachedClientConfiguration();
                mcache_config.Servers.Add(new IPEndPoint(IPAddress.Parse(localhost), mcache_port));
                mcache_config.Protocol = MemcachedProtocol.Text;
                mcache_client = new Enyim.Caching.MemcachedClient(mcache_config);

                DataBase_0.Open();
                DataBase_1.Open();
                DataBase_2.Open();
                DataBase_3.Open();
                DataBase_4.Open();
                DataBase_info.Open();
                DataBase_0.Close();
                DataBase_1.Close();
                DataBase_2.Close();
                DataBase_3.Close();
                DataBase_4.Close();
                DataBase_info.Close();
            }
            catch (SqlException)
            {
                print_message("Connection failed. DataBases states:\n" +
                    "\nDataBase #1: " + DataBase_0.State.ToString() +
                    "\nDataBase #2: " + DataBase_1.State.ToString() +
                    "\nDataBase #3: " + DataBase_2.State.ToString() +
                    "\nDataBase #4: " + DataBase_3.State.ToString() +
                    "\nDataBase #5: " + DataBase_4.State.ToString() +
                    "\nDataBase info: " + DataBase_info.State.ToString());
            }
            catch (Exception error) 
            {
                print_message("MainForm_Load: " + error.Message);
            }

            if (this.Request.QueryString.ToString().Length > 0)
            {
                var str = this.Request.QueryString.GetValues("user_id");
                //print_message(str[0].ToString());
                userid_textBox.Text = str[0];
                get_user_info();
            }
        }
Пример #23
0
		public void ProgrammaticConfigurationTest()
		{
			// try to hit all lines in the config classes
			MemcachedClientConfiguration mcc = new MemcachedClientConfiguration();

			mcc.Servers.Add(new System.Net.IPEndPoint(IPAddress.Loopback, 20000));
			mcc.Servers.Add(new System.Net.IPEndPoint(IPAddress.Loopback, 20002));

			mcc.NodeLocator = typeof(DefaultNodeLocator);
			mcc.KeyTransformer = typeof(SHA1KeyTransformer);
			mcc.Transcoder = typeof(DefaultTranscoder);

			mcc.SocketPool.MinPoolSize = 10;
			mcc.SocketPool.MaxPoolSize = 100;
			mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 10);
			mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 30);

			new MemcachedClient(mcc);
		}
Пример #24
0
        private void CreateManager()
        {
            serverList = memCachedConfigInfo.ServerList.Split(',');
            MemcachedClientConfiguration config = new MemcachedClientConfiguration();
            foreach (string server in ServerList)
            {
                config.Servers.Add(new IPEndPoint(
                    IPAddress.Parse(server.Substring(0, server.LastIndexOf(':'))), Int32.Parse(server.Substring(server.LastIndexOf(':') + 1))));
            }
            config.Protocol = MemcachedProtocol.Text;
            config.Authentication.Type = typeof(PlainTextAuthenticator);
            config.SocketPool.MaxPoolSize = memCachedConfigInfo.MaxPoolSize;
            config.SocketPool.MinPoolSize = memCachedConfigInfo.MinPoolSize;
            config.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, memCachedConfigInfo.ConnectionTimeout);
            config.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, memCachedConfigInfo.ReceiveTimeout);
            config.SocketPool.DeadTimeout = new TimeSpan(0, 0, memCachedConfigInfo.DeadTimeout);
            config.SocketPool.QueueTimeout = new TimeSpan(0, 0, memCachedConfigInfo.QueueTimeout);

            mc = new MemcachedClient(config);
        }
        private static void TryInitializeClient(IDictionary<string, string> options)
        {
            if (_memcachedClient != null)
            {
                return;
            }

            var port = int.Parse(options["port"]);
            var userName = options["userName"];
            var password = options["password"];
            var zone = options.ContainsKey("zone") ? options["zone"] : string.Empty;
            var addresses = Dns.GetHostAddresses(options["hostName"]);

            var config = new MemcachedClientConfiguration();
            config.Servers.Add(new IPEndPoint(addresses[0], port));
            config.Protocol = MemcachedProtocol.Binary;
            config.Authentication.Type = typeof(PlainTextAuthenticator);
            config.Authentication.Parameters["userName"] = userName;
            config.Authentication.Parameters["password"] = password;
            config.Authentication.Parameters["zone"] = zone;

            _memcachedClient = new MemcachedClient(config);
        }
 /// <summary>
 /// Initializes the Memcached Client.
 /// 
 /// Method should only be called ONCE.
 /// </summary>
 /// <param name="clientConfiguration">An instantiated MemcachedClientConfiguration</param>
 public static void Initialize(MemcachedClientConfiguration clientConfiguration)
 {
     _memcachedClient = new MemcachedClient(clientConfiguration);
 }
Пример #27
0
 static Registry()
 {
     config = new MemcachedClientConfiguration();
     client = new MemcachedClient(config);
 }
Пример #28
0
        private void InitMC()
        {
            if (null == m_oMcConfig)
            {
                m_oMcConfig = new MemcachedClientConfiguration();

                string sServerName = ConfigurationManager.AppSettings["utils.taskresult.cacheddb.mc.server"] ?? "localhost:11211";

                m_oMcConfig.AddServer(sServerName);
                m_oMcConfig.Protocol = MemcachedProtocol.Text;
            }
        }
Пример #29
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            // or just initialize the client from code
            var nscc = new MembaseClientConfiguration();

            nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
            nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default"));
            //nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default"));
            //nscc.Credentials = new NetworkCredential("A", "11111111");
            //nscc.Bucket = "content";
            //nscc.BucketPassword = "******";

            var client = new MembaseClient(nscc);
            Console.WriteLine("Store = " + client.Store(StoreMode.Set, "4q", 1, new TimeSpan(0, 0, 4)));

            Console.WriteLine("Setting expiration to the far future.");
            //Console.ReadLine();

            client.Touch("4q", DateTime.Now.AddDays(1));

            Console.WriteLine("Wait for 4 sec.");
            Console.ReadLine();

            Console.WriteLine(client.Get("4q") ?? "<null>");

            //new MembaseClient(nscc, "data", "data").Store(StoreMode.Set, "q4", 2);
            //new MembaseClient(nscc, "feedback", null).Store(StoreMode.Set, "q4", 2);

            Console.ReadLine();

            //nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory();
            //nscc.BucketPassword = "******";

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_"));

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_"));

            Console.ReadLine();

            return;

            var mcc = new MemcachedClientConfiguration();
            mcc.AddServer("192.168.2.200:11211");
            mcc.AddServer("192.168.2.202:11211");

            mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            StressTest(new MemcachedClient(mcc), "TesT_");

            return;

            var nc = new MembaseClient(nscc, "content", "content");

            var stats1 = nc.Stats("slabs");
            foreach (var kvp in stats1.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);

            var nc2 = new MembaseClient(nscc, "content", "content");

            var stats2 = nc2.Stats();
            foreach (var kvp in stats2.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
        }
Пример #30
0
 public EideticConfigurator()
 {
     Configuration = new DefaultMemcachedConfiguration();
 }