Memcache Simple to use

Source: Internet
Author: User

1:memcache in the download https://pan.baidu.com/s/1dFnB3NV/08

Simple installation: Just click on the Memcached.exe file in the folder. But each use needs double-click, is troublesome. So you can also install to Windows services

2: Install memcache into Windows services

2.1 Start the Command window as an administrator

Command: F:

CD F:\memcache

memcached-d Install

memcached-d start

3: Test

After entering the command prompt window via cmd

Telnet 127.0.0.1 11211

Stats

4 C # operation Memcache required DLL files are also in the Baidu Cloud Disk 08 folder under Memcachedonetlibraryall

4.1 Create a control bar application and reference the file

Add a file to the project's Lib folder, add a reference Commons.dll,icsharpcode.sharpziplib.dll,log4net.dll,memcached.clientlibrary.dll

usingmemcached.clientlibrary;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacememcachetest{classProgram {[STAThread]Static voidMain (string[] args) {             //Specify the IP address and port number of the Memcache             string[] ServerList = {"127.0.0.1:11211","10.0.0.132:11211" }; //Initialize PoolSockiopool pool =sockiopool.getinstance (); Pool.              Setservers (serverlist); Pool. Initconnections=3; Pool. Minconnections=3; Pool. MaxConnections=5; Pool. Socketconnecttimeout= +; Pool. Sockettimeout= the; Pool. Maintenancesleep= -; Pool. Failover=true; Pool. Nagle=false; Pool.              Initialize (); //get the client instance--find the server based on the IP address (hash algorithm takes the remainder)//responsible for connecting the service sidememcachedclient MC =Newmemcachedclient (); Mc. EnableCompression=false; Console.WriteLine ("------------Test-----------"); //store data to the Memcache service, key-value pairsMc. Set ("Test","My value");//stores the data to the cache server, where the string "My value" is cached, and key is "test"//determine if a value is in a key-value pair             if(MC. Keyexists ("Test"))//test cache has a project with key test{Console.WriteLine ("test is Exists"); Console.WriteLine (MC. Get ("Test"). ToString ());//get the item with key test in the cache             }             Else{Console.WriteLine ("Test not Exists");              } console.readline (); Mc. Delete ("Test");//Remove the item in the cache with key test              if(MC. Keyexists ("Test") {Console.WriteLine ("test is Exists"); Console.WriteLine (MC. Get ("Test").             ToString ()); }             Else{Console.WriteLine ("Test not Exists");                          } console.readline (); Sockiopool.getinstance ().  Shutdown (); //Close the pool, close sockets         }            }}
memcachetest

Operation Result:

5: Uninstalling Memcache from the Windows service

4.1 Start the Command window as an administrator

4.2 Navigate to the folder where Memcached.exe is located

Command: F:

CD F:\memcache

memcached-d stop

memcached-d Uninstall

Memcache Simple to 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.