Environment preparation:
1. download and install the memcached server for Windows:
:
Http://www.splinedancer.com/memcached-win32/
Installation Method After download:
Decompress the ZIP file to a directory, such as D: \ dB \ memcached. the following file name is memcached.exe.
Start cmd as an administrator and go to the decompressed directory. In this example, D: \ dB \ memcached and run the following command:
// Install memcached as a Windows Service
Memcached.exe-D install
// Start the service and listen to port 11211 of the Local Computer
Memcached.exe-l localhost-P 11211-d start
2. Download nmemcached. Client ------ memcached client for C.
:
Http://nmemcached.codeplex.com/
3. Create an app (console, winform, or web) and Add a reference to nmemcached. Client. dll.
3.1 Add the memcached configuration information in APP. config (or web. config) of the app, for example:
<Configsections> <section name = "nmemcached. client "type =" nmemcached. client. configuration. nmemcachedconfigurationsection, nmemcached. client "/> </configsections> <startup> <supportedruntime version =" v4.0 "SKU = ". netframework, version = v4.0 "/> </startup> <nmemcached. client useutc = "false"> <connectionprovider> <Add Server = "127.0.0.1" Port = "11211"> </Add> </connectionprovider> </nmemcached. client>
3.2 compiling example Code :
Using (VAR client = nmemcached. client. memcachedclient. create () {client. connectionerror + = new system. eventhandler <nmemcached. client. connectioneventargs> (client_connectionerror); client. flushall (); string key = "key1"; student s = new student () {name = "zhaoy", age = 111}; responsecode resp = client. set (key, S, datetime. now. addminutes (10); object keyval = client. get (key); console. writeline (resp. tostring (); console. writeline (keyval);} // using
4. Connect to memcached through command line
4.1 for Windows 7, you must enable the Telnet client first.
4.2 open the CMD command line and enter the following command to connect to memcached:
Telnet fig 11211
Enter
Then you can run the following command to interact with memcached:
1, stats
Enter
// Description: Lists common memcached information, such as the space used and cache items.
2, set key1 0 0 8
Enter
12345678
Enter
// Description: The write key is key1, the value is 12345678, and key1 is the key name.
For command instructions, see the followingArticle:
Http://www.cnblogs.com/jeffwongishandsome/archive/2011/11/06/2238265.html