Summary introduction of Memcache and summary of some commands

Source: Internet
Author: User

What is 1.1memcached?

Take a look at some official explanations:

1 free&opensource,high-performance,distributed  Memory Object Caching system

Free & Open source, high performance, distributed memory object cache system
An established NoSQL application developed by Livejounal's Danga company

2.1linux compiling the memcached

Prepare the build Environment: 2 after Linux compilation, need Gcc,make   after Linux system networking, install 5 #yum installed gcc make cmake autoconf libtool with the following command

Compiling memcached
Memcached relies on the Libevent library, so we need to install Libevent first.

Download the latest stable version (stable version) to libevent.org and memcached.org respectively.

Compile the libevent first, then compile the memcached,

Specify the path to libevent when compiling memcached.

The process is as follows: Assuming the source code under/USR/LOCAL/SRC, installed under/usr/local

1 #tar zxvf  libevent-2.0.21-stable.targz 2 #cd  libevent-2.0.21-Stable 3 #./configure--prefix=/usr/ local/#如果出错, read the wrong message, see the reason, is generally missing Library 5 # make && make  install 6 # tar zxvf  memcached-1.4.5. tag.gz 7 # cd< c9/>memcached-1.4.5 8 #/configure  --prefix=/usr/local/memcached 9--with-libevent=/usr/local/  Libevent10 # make && make install     

Memcached Start: (we can select some parameters at startup by--help)

1 #/usr/local/memcached/bin/memcached-m64-p11211-unobody  -.... 8 Slab class 9:chunksize Perslab 1747 9 Slab class 10:chunksize 752 Perslab 139410 Slab class 39:chunksize 493552 pers Lab 211 Slab Class 40:chunksize 616944 Perslab Slab class 41:chunksize 771184 Perslab 113 Slab class 42:chunksize 1048 576 Perslab 1

If you want to understand the meaning of parameters such as-m-p, you can view the help through Memcached-h:

1-p <num> TCP port number to ListenOn (default:11211)//Monitor 2ports 3-u <num> UDP port number to ListenOn (default:0, off) 4-s <file> unixsocket path to ListenOn ( Disables network support) 5-a <mask> access mask for Unixsocket,inoctal (default0700) 6-l <ip_addr> I Nterface to Listenon,default are in Drr_any 7-D start Tellmemcachedtostart 8-D restart Tellrunningmemcachedtodoag Racefulrestart 9-d stop| shutdown tellrunningmemcachedtoshutdown10-d Install installmemcachedservice//Register memcached as a service-D Uninstall Uninstall memcached Service12-R maximize core file Limit13-u <username>assume identity of <USERNAME>
             
               (only if run as root) 14-m <num>
               max memory to usage for items inmegabytes,defaultis6415 mb//assigned to memcached maximum RAM -m return error on memory exhausted (rather than removing17 items)
             
         

memcached Connection:

Memcached client-to-server communication is simpler, using a text-based protocol rather than a binary protocol. 2 (so is the HTTP protocol), so we can interact with memcached with Telnet.

Open another terminal and run the telnet command (do not turn off the memcached terminal):

#格式telnet host Port2 #telnet localhost 112113 trying::1Connected to localhost.5 Escape character is ' ^] '.

Memcached's command:

Key  flag  flag, required for a positive integer 7 expire validity

Length of the long cache (in bytes)
memcached Basic Text protocol, the transfer of something, understood as a string to store. 3 Think: let you save a PHP object, and a PHP array, what to do? 4 A: Serialize into a string, and when it goes out, it is naturally deserialized into an object/array/This time  , The significance of flag is reflected. 6 For example, 1 is a string, 2 reverses the array 3, deserializes the object .....
Set the expiration date of the cache in 3 formats 3 1: Set the number ofseconds, from the start of the set, the nth second after the failure. 4 2 For example, in the group buying site, the cache of a group to 12:00 noon expires. Add key 0 137920999966 3: set to 0. Not automatically invalidated. 

Note: There is a misunderstanding, set to 0, permanent effective. Wrong.

1 1: When compiling memcached, specify a maximum constant, which is 30 days by default.
So, even if it is set to 0, it will expire after 30 days. 3 2: It may not be more than 30 days, it will be squeezed out by new data.

Delete Deletes the deleted key [time seconds] to delete the specified key. If the optional parameter is time, the key is deleted and the key is not allowed to operate within the time seconds after the key is deleted.
Replace key flag expire Length3 parameter is exactly the same as add, not individually written
Get Key3 Returns the value of key
The parameters are the same as the add,replace, but the functions are different. 3 4 When you use Add, key does not exist to establish this key value.
Set key flag Expire Leng 3 If the server does not have this key----> added Effect 4 If the server has this key----> modified effect. 5 as shown in the figure, the name is already present, The date does not exist. Set can successfully set their 

? INCR,DECR command: Increase/Decrease the size of the value
Syntax: INCR/DECR key num
Example:

Set age 0 0 228storedget agevalue age 0 228ENDINCR age 129incr age 231decrage-decr Age 228   
1 Application Scenarios------   pressure is huge. 4 can use memcached incr/ per person grab single main in memory operation, speed very fast, 6 Rob to count<=1000 number of people, get an order number, Go to another page and pay slowly 

Statistics Command: Stats:

1 stat PID 22443//Process number 2 stat uptime 17543398//Duration of Operation 3 Stat time 1438505866 4 stat version 1.4.22 5 stat libevent 2.0. 20-Stable 6 stat pointer_size 7 stat rusage_user 63.916283 8 stat rusage_system 36.312479 9 STAT curr_connections 510 Stat Total_connections 3611 stat connection_structures 712 stat Reserved_fds stat cmd_get 1514 stat cmd_set 615 stat cmd_ Flush Cmd_touch STAT 017 stat get_hits 918 stat get_misses 619 Stat delete_misses 020 stat delete_hits 121 stat incr_m  Isses 022 Stat incr_hits 023 stat decr_misses 024 stat decr_hits 025 stat cas_misses 026 stat cas_hits 027 Stat cas_badval 028 Stat touch_hits 029 Stat touch_misses 030 Stat AUTH_CMDS 031 stat auth_errors 032 stat bytes_read 581533 Stat bytes_w Ritten 210834 stat limit_maxbytes 6710886435 stat Accepting_conns 136 stat listen_disabled_num 037 Stat Threads 438 Stat C Onn_yields 039 stat hash_power_level 1640 stat hash_bytes 52428841 stat hash_is_expanding 042 stat malloc_fails 043 Stat b Ytes 7444 stat curr_items 145 stat total_items 546 stat expired_unfetched 047 stat evicted_unfetched 048 Stat Evictions 04 9 STAT Reclaimed STAT crawler_reclaimed 051 STAT lrutail_reflocked 052 53  The cache has an important concept: Hit ratio. 54 hit Rate is: (Number of queries to data/total number of queries) *100%55 as above, 13/(13+7) =60+%, the hit rate.

Summary introduction of Memcache and summary of some commands

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.