- tool:
- memcached-1.2.6-win32-bin.zip memcached server Program (For Win)
- memcached manager memcached management tool in win
- memcached. net client library C #/. net memcached client DLL
- install and configure the memcached Server
- download the memcached-1.2.6-win32-bin.zip file and decompress it to get memcached.exe, which is the main program of memcached. For example, we put it under c: \ Program Files \ memcached on the memcached server.
- download and install memcached manager to manage the memcached server.
open memcached manager, click Add Server, and enter the server information. I have installed memcached locally ., After filling in the fields, click Apply. If successful, the server will appear on the right.
click Add instance to add a memcached instance. Here are some configuration information. IP address, port, memory, and so on. After you click Apply, you will be prompted if you are starting now. Here we select
. After successful, an instance is found on the right, the server configuration is complete.
- client call
- first download memcached. net client library client class library, decompress it to obtain a memcacheddotnet directory with a bunch of files.
to test memcached, we create a web project. Reference memcached. clientlibrary. dll. This dll is stored in memcacheddotnet \ trunk \ clientlib \ SRC \ clientlib \ bin \ 2.0 \ release
- it is easy to use, with one memory and one fetch. Let's get two simple pages.
Add using
UsingMemcached. clientlibrary;
Storage:
Code:
Protected
VoidPage_load (ObjectSender,EventargsE)
{
If(! Ispostback)
{
String[] Serverlist = {server. Text };
SockiopoolPool =Sockiopool. Getinstance ();
Pool. setservers (serverlist );
Pool. initconnections = 3;
Pool. minconnections = 3;
Pool. maxconnections = 5;
Pool. socketconnecttimeout = 1000;
Pool. Fig = 3000;
Pool. maintenancesleep = 30;
Pool. Failover =True;
Pool. Nagle =False;
Pool. initialize ();
}
}
Protected
VoidSetvalue_click (ObjectSender,EventargsE)
{
MemcachedclientMC =New
Memcachedclient();
MC. enablecompression =False;
MC. Set (key. Text, value. Text );
Response. Write ("<SCRIPT> alert ('OK') </SCRIPT>");
}
Take:
Code:
Protected
VoidGetvalue_click (ObjectSender,EventargsE)
{
String[] Serverlist = {server. Text };
SockiopoolPool =Sockiopool. Getinstance ();
Pool. setservers (serverlist );
Pool. initconnections = 3;
Pool. minconnections = 3;
Pool. maxconnections = 5;
Pool. socketconnecttimeout = 1000;
Pool. Fig = 3000;
Pool. maintenancesleep = 30;
Pool. Failover =True;
Pool. Nagle =False;
Pool. initialize ();
MemcachedclientMC =New
Memcachedclient();
MC. enablecompression =False;
StringValue = (String) MC. Get (key. Text );
Value. Text = value;
}
See the results:
Click Add to save to memcached.
Click get. The result is displayed.
OK. You can also encapsulate the client code to make the call easier.