First, Prepare:
memcaced Service side: Http://files.cnblogs.com/sjns/memcached_en32or64.rar
Memcaced Client class Library: Http://files.cnblogs.com/sjns/Memcached.ClientLibrary.rar
Which service the detection data is saved in: SECURECRT (note: This software has not been used, this is only recorded later in the verification of time)
Second, install the memcaced service end
Copy the Memcached.exe to any directory. Install with the cmd command. ( Note: Run command prompt again under Win7 to run with administrative identity )
Installation: memcached.exe-d Install
Start: memcached.exe-d start
Uninstall: memcached.exe-d Uninstall
Third, create the program, I use the console application here.
Add the Memcaced client class library to the reference.
Sockiopool is a socket connection pool provided by the memcached client, which, in layman's words, is the object that exchanges data with the memcached server side.
Note: Sockiopool is initialized at the start of the application, and we can put this job on GLOBAL. ASAX. CS in the Application_Start method.
Okay, here's my Code, a demo.
Static voidMain (string[] args) { Char[] Separator = {',' }; string[] ServerList =New string[] {"127.0.0.1:11211" }; Try{Sockiopool Pool=sockiopool.getinstance (); Pool. Setservers (serverlist); Pool. Initconnections=3; Pool. Minconnections=3; Pool. MaxConnections= -; Pool. Socketconnecttimeout= +; Pool. Sockettimeout= the; Pool. Maintenancesleep= -; Pool. Failover=true; Pool. Nagle=false; Pool. Initialize (); Memcachedclient MC=Newmemcachedclient (); Mc. Set ("123","123123123"); Console.WriteLine ("enter the key to query"); stringKey =Console.ReadLine (); Console.WriteLine (MC. Get (key)); Console.WriteLine ("enter the key to be modified"); String Ukey=Console.ReadLine (); Console.WriteLine ("Enter the value to modify"); String Uval=Console.ReadLine (); Console.WriteLine (MC. Set (Ukey, uval)); Console.WriteLine ("Key:"+ Ukey +"The value has been modified. as follows:"); Console.WriteLine ("Value:"+uval); } Catch(Exception err) {//Here you can record the error with Log4net! } }
Here's how it works:
. NET app memcached cache demo (non-reprinted, file valid)