. net/c# memcached installation and basic use

Source: Internet
Author: User
Tags memcached windows net serialization set socket

: memcached Windows 64-bit

1, extract to the specified directory, such as: D:\Memcached\memcached-win64-1.4.4-14.
2, open the command window with CMD, go to the extracted directory, enter "memcached.exe-d install".
3, open the Control Panel, open the service, you can see memcached already on the above can, if not started, then manually start.

4. Use the Telnet command to verify that the cache server is available.

Telnet 10.1.19.61 11211

Start with nothing to show, enter after the command stats to view statistics, such as, the server is functioning properly.

Three, the parameter introduction

1, the above installation and start are in the default environment, in the installation can set the following parameters:
-P Listening Port
-L connected IP address, default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown Close the running memcached service
-D Install memcached service
-d Uninstall Uninstall memcached service
-U Run as (only valid when running as root)
-m maximum memory usage, in megabytes. Default 64MB
-M running out of memory and returning an error instead of deleting an 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 Display Help

Four, code examples

 Static voidMain (string[] args) {            //Server-side list            string[] ServerList = {"127.0.0.1:11211" }; //Initialize PoolSockiopool sock =sockiopool.getinstance (); Sock. Setservers (serverlist);//Add Server ListSock. Initconnections =3;//set initial number of connection poolsSock. Minconnections =3;//set the minimum number of connectionsSock. MaxConnections =5;//set maximum number of connectionsSock. Socketconnecttimeout = +;//sets the socket timeout for the connection. Sock. Sockettimeout = the;//Set socket timeout readSock. Maintenancesleep = -;//Sets the sleep time that the maintenance thread runs.            If set to 0, then the maintenance thread will not start; //Gets or sets the fault flag for the pool. //If this flag is set to true then the socket connection fails,//An attempt is made to return a socket from another server if it exists. //if set to false, a socket is obtained if one exists. Otherwise, NULL is returned if it cannot connect to the requested server. Sock. Failover =true; //If False, the Nagle algorithm is closed for all created sockets. Sock. Nagle =false; Sock.            Initialize (); //get the client instanceMemcachedclient memcached =Newmemcachedclient (); //whether to enable compressed dataMemcached. EnableCompression =false; Console.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~~memcached Set"); //stores cached data. //If the data does not exist on the server for this key, or if the key is deleted, the specified value will not be saved. //when the expiration time arrives, the server automatically deletes the key value. //If compression is enabled, data compression is longer than the threshold data will be stored in compressed form. //in the current version, all objects are used.            NET serialization. //parameter Description://Key : The key for the cache. Value: Cache object. Expiry: Expiration time. hashcode: If not null, the interpretation hash code is used//asstring: Storing the object as a stringMemcached. Set ("test1","test1"); Console.WriteLine (memcached. Get ("test1")); Console.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~~memcached Add, add then call set the same key value set will overwrite the value of Add"); Memcached. ADD ("test2","value2"); Console.WriteLine (memcached. Get ("test2")); Memcached. Set ("test2","value1 value2"); Console.WriteLine (memcached. Get ("test2")); Console.WriteLine ("Memcached Replace"); //updates the data on the server, specifying the key and value. Memcached. Replace ("test2","Value3"); Console.WriteLine (memcached. Get ("test2")); Console.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~memcached whether the key value exists"); if(memcached. Keyexists ("test2") {Console.WriteLine ("Key Test2 exists"); } Console.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~memcached Deleting Data"); Memcached. ADD ("test4","Value4"); Console.WriteLine ("test4==>"+ memcached. Get ("test4")); Memcached. Delete ("test4"); if(!memcached. Keyexists ("test4") {Console.WriteLine ("Test4 has deleted"); } Console.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~memcached Data Expiration"); Memcached. ADD ("Test5","Value5", DateTime.Now.AddMilliseconds ( the)); Console.WriteLine (memcached. Get ("Test5")); System.Threading.Thread.Sleep (6000); Console.WriteLine ("Expired:"+ memcached. Get ("Test5"));            Console.read (); Sockiopool.getinstance ().  Shutdown (); //Close the pool, close sockets}

PS. Reference Articles

Http://www.jb51.net/article/30334.htm

Http://www.cnblogs.com/xiaogangqq123/archive/2011/03/11/1981114.html

. net/c# memcached installation and basic use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.