Ubuntu Tencent cloud host installs distributed memcache server, an example of connecting cloud host for storage in C#

Ubuntu Tencent cloud host installs distributed memcache server, an example of connecting cloud host for storage in C# (github code: https://github.com/qq719862911/MemcacheTestDemo)

1. Tencent Cloud installs the memcache server and starts the server.

1) Install the Memcache server 

sudo apt-get install memcached 

After installing the Memcache server, we need to start the service: 

memcached -d -m 128 -p 11111 -u root 


Here we need to explain the startup parameters of the memcached service: 

-p listen port 
-l IP address of the connection, the default is the local machine 
-d start to start the memcached service 
-d restart to restart the memcached service 
-d stop|shutdown to close the running memcached service 
-d install to install the memcached service 
-d uninstall to uninstall the memcached service 
- u run as root (only valid when running as root) 
-m maximum memory usage, in MB. Default 64MB 
-M Return error when memory is exhausted, instead of deleting item 
-c maximum number of simultaneous connections, default is 1024 
-f block size growth factor, default is 1.25-n minimum allocated space, key+value+flags default is 48 
- h show help 

 

2. Connect the storage data of cloud memcache in C#.

1) Nuget installation: EnyimMemcached (memcache client in C#)

2) Write this code in the main of the console program.

 

    static void Main(string[] args)
        {
            MemcachedClientConfiguration mcConfig = new MemcachedClientConfiguration();
            mcConfig.AddServer( " 119.29.176.32:11111 " );//The public network address of the cloud server plus the port of memcache
             using (MemcachedClient client = new MemcachedClient(mcConfig))
            {
                client.Store(Enyim.Caching.Memcached.StoreMode.Set, "name", "haiyi",TimeSpan.FromSeconds(30));
                   var name =  client.Get<string>("name");
                 Console.WriteLine(name);
                /*调试  模式 存储数据*/
                //IStoreOperationResult result = client.ExecuteStore(Enyim.Caching.Memcached.StoreMode.Set, "name", "haiyi", TimeSpan.FromSeconds(30));
                //Console.WriteLine( result.StatusCode+"  is success: "+result.Success+ "  InnerResult" + result.InnerResult);
                //  var getResult =  client.ExecuteGet<string>("name");
                //Console.WriteLine(getResult.InnerResult+"  statuCode:"+getResult.StatusCode+"  success:"+getResult.Success+ "  value=" +getResult.Value); //+getResult.Exception.Message
            }
            Console.Read();
        }

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324622379&siteId=291194637