Install Memcached in CentOS 5.4

Source: Internet
Author: User

In general, CentOS has installed the libevent binary library by default, but no header file for development is installed.
Therefore, you can use the following command to install:

Yum install libevent-devel

Next, you can download the latest memcached version.
Decompress:
Tar-xzvf memcached-1.4.4.tar.gz

Configuration:
Cd memcached-1.4.4
./Configure-with-libevent =/usr/

Note: If the libevent is not installed in the/usr directory, You need to copy/link the libevent-1.4a.so.1 to/usr/lib, otherwise memcached will report that the libevent cannot be found during configuration.

Compile:
Make

Installation:
Make install

Start:
Memcached-l 192.168.10.60-d-p 11212-u nobody-m 1024

In the preceding command,-d indicates that memcached is started using daemon. The combination of-l and-p indicates that memcached is listened to on port 11212 of 192.168.10.60 (if-p is not used to specify the port number, memcached runs on port 11211). The-u table indicates that the running user is nobody, and-m indicates that the user is allocated 1024 MB of memory.

Test:
You can use telnet to connect to port 11212 of 192.168.10.60. After the connection is successful,
First add a key-value pair to memcached. The key is test1 (the specific meaning indicated by 0 0 10 is described in detail in the next article), and the value is testing001:
Set test1 0 0 10
Testing001
STORED

Then retrieve the value corresponding to test1 from memcached:
Get test1
VALUE test1 0 10
Testing001
END

Note: The system output content is in bold.

If similar output is displayed, memcached has been correctly configured and started successfully.

Memcached basic data operation command

There are only four basic commands for memcached data storage and retrieval.
The following describes how to use telnet to interact with memcached and the four basic commands.
Assume that the memcached server is on the local machine and listens to the default port 11211.

Telnet to memcached:
Telnet fig 11211

SET: Add a new entry to memcached, or replace existing entries with new data.

Set test1 0 0 10
Testing001
STORED

ADD: stores data only when the key does not exist. If a key already exists, the response of NOT_STORED will be returned.

Add test1 0 0 10
Testing002
NOT_STORED
Add test2 0 0 10
Testing002
STORED

REPLACE: stores data only when the key already exists. If a key does not exist, the response of NOT_STORED is returned.

Replace test1 0 0 10
Testing003
STORED
Replace test3 0 10
Testing003
NOT_STORED

GET: returns data from memcached. When data is returned from the cache, the key name, flag value, and returned value length are obtained in the first row. The real data is in the second row, and the END is returned. If the key does not exist, the END is returned in the first row.

Get test1
VALUE test1 0 10
Testing003
END
Get test4
END
Get test1 test2
VALUE test1 0 10
Testing003
END

Note: As shown above, you can include multiple keys separated by spaces in a request. When multiple keys are requested, only the keys with stored data are returned. Memcached will not respond to keys that do not store Data.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.