Memcached features:
Simple Protocol
Libevent-based event processing
Built-in memory storage
Distributed memcached does not communicate with each other
1. Simple protocol:
Using simple text-based protocols, you can use Telnet to save data and obtain data on memcached.
2. Based on libevent:
Encapsulates the event processing functions of Linux and other operating systems into a unified interface, enabling high performance in Linux, BSD, and other operating systems.
3. built-in memory storage:
To improve performance, data stored in memcached is stored in the built-in storage space of memcached. If the content capacity reaches the specified value, it is based on LRU (least recently used) the algorithm automatically deletes unused caches.
4. Distributed memcached non-communication
The memcached server does not have distributed functions. Each memcached does not communicate with each other to share information. The distribution depends entirely on the implementation of the client.
Install memcached in Linux:
Sudo Yum install libevent-Deval
Wget http: // ip/XXXXX
Tar zxf memcached-version.tar.gz
CD memcached-version
./Configure
Make
Sudo make install
Start memcached:
/Usr/local/bin/memcached-P 11211-M 64 m-VV
Option description:
Option description
-P uses the TCP port. The default value is 11211.
-Maximum memory size of M. The default value is 64 m.
-VV is started in very vrebose mode. debugging information and errors are output to the console.
-D is started as a daemon in the background
-H help
<?php$memcache = new Memcache;$memcache->connect('localhost', 11211) or die ("Could not connect");$version = $memcache->getVersion();echo "Server's version: ".$version."<br/>\n";$tmp_object = new stdClass;$tmp_object->str_attr = 'test';$tmp_object->int_attr = 123;$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";$get_result = $memcache->get('key');echo "Data from the cache:<br/>\n";var_dump($get_result);?>
Memcache can save data by using the following methods:
Add
Replace
Set
Usage:
$ Add = $ memcache-> Add ('key', 'value', 'duration ');
$ Replace = $ memcache-> Replace ('key', 'value', 'duration ');
$ Set = $ memcache-> set ('key', 'value', 'duration ');
How to get data from memcache:
Get
Usage:
$ Getresult = $ memcache-> get ('key ');
Var_dump ($ getresult );