Memcache Memory Object Cache System
Introduction:
Memcached is a high-performance distributed memory storage object Cache System for dynamic WEB applications to reduce database load.
It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed.
Memcached is based on a hashmap that stores key/value pairs.
Its daemon is written in C, but the client can write it in any language and communicate with the daemon through the Memcached protocol without providing redundancy; when a server stops running or crashes, all key-value pairs placed on the server will be lost.
:
Http://jaist.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
Https://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
1. Install the libevent Library
# This is an asynchronous event notification library on which memcached depends
shell > tar zxf libevent-2.0.22-stable.tar.gz -C ../shell > cd ../libevent-2.0.22-stable/shell > ./configure ; make ; make install
2. Install Memcached
shell > tar zxf memcached-1.4.15.tar.gz -C ../shell > cd ../memcached-1.4.15/shell > ./configure --prefix=/usr/local/memcached ; make ; make install
3. Start Memcached
shell > /usr/local/memcached/bin/memcached -d -m 512 -p 11211 -u nobody -c 4096
#-L listening address. memcache has no authentication function. It is strictly prohibited to use it without protection.
#-D run as a daemon
#-M specifies the size of memory allocated, in MB
#-P listening port
#-U running user
#-C maximum number of concurrent connections
#-P pid file storage location
#-F growth factor
# Startup Error
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
# Solution
shell > find / -name libevent-2.0.so.5/usr/local/lib/libevent-2.0.so.5
shell > ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/
shell > /usr/local/memcached/bin/memcached -d -m 512 -p 11211 -u nobody -c 4096
shell > netstat -anpt | grep memcachedtcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 13465/memcachedtcp 0 0 :::11211 :::* LISTEN 13465/memcached
# When the instance is successfully started, it listens to all IP addresses, including ipv6, Which is insecure. It is best to specify the IP address of the listener.
4. Test Memcached
# Syntax
Command <key> <flags> <expiration time> <bytes> <value> command includes: set add replace get deletekey key used to find the cache value. flags can include Integer Parameters of key-value pairs, the client uses it to store additional information about the key-Value Pair expiration time the length of time the key-value pair is saved in the cache (in seconds, 0 indicates permanent) byte point value stored by bytes in the cache (always in the second row)
Shell> telnet 127.0.0.1 11211 # log on to memcachedTrying 127.0.0.1... connected to 127.0.0.1.Escape character is '^]'. set id 0 0 5 # Save a VALUE 12345 STOREDget id # VALUE id 0 512345 ENDreplace id 0 0 5 # update VALUE 88888 STOREDget id # Check whether VALUE id 0 588888 ENDquit # exit connection closed by foreign host. shell> telnet 127.0.0.1 11211 Trying 127.0.0.1... connected to 127.0.0.1.Escape character is '^]'. get id # log on again and save VALUE id 0 588888 ENDquitConnection closed by foreign host. shell> telnet 127.0.0.1 11211 Trying 127.0.0.1... connected to 127.0.0.1.Escape character is '^]'. get idVALUE id 0 588888 ENDdelete id # Delete value DELETEDget idENDquitConnection closed by foreign host.
Install and configure Memcached source code in CentOS 6.6
Memcached installation and startup script
Performance problems of using Memcached in PHP
Install Memcached in Ubuntu and its command explanation
Install and apply Memcached
Use Nginx + Memcached's small image storage solution
Getting started with Memcached
For details about Memcached, click here
Memcached: click here
This article permanently updates the link address: