View memcache server through telnet connection

Keywords: Unix

memcache, as an excellent out-of-process cache, is often used in highly concurrent systems Framework Medium. This article mainly talks about how to check memcache running status and manage and maintain its key through telnet tool. Assume the memcache installation directory: / usr/local/memcached

          
1. Start memcache

  1. [root@localhost ~]# /usr/local/memcached/bin/memcached -d -m 512  -u root -l 192.168.119.70 -p 12000 -c 512 -P /usr/local/memcached/memcached.pid  

Detailed start-up parameters
- d: Start as a daemon. If this parameter is not specified, memcache automatically closes when the ctrl+c command is completed
- m: The largest unit of memory allocated to memcache is m, which defaults to 64m.
- u: Specify the user who runs memcache
- l: Specify the ip address to listen on
- p: specify the tcp port number to listen on, and the udp port can be specified by - u. The default is 11211.
- c: Maximum number of concurrent connections
- P: File of error process id
After memcache is started, we can connect memcache through telnet and manage it simply.

2. telnet connection memcache

  1. [root@localhost ~]# telnet 192.168.119.70 12000   
  2. Trying 192.168.119.70...  
  3. Connected to 192.168.119.70 (192.168.119.70).  
  4. Escape character is '^]'.   

After successful connection, memcache can be operated and managed. Common commands are:

I. Adding and Modifying

Command format: < command > < key > < flags > < exptime > < bytes > r n < data block > r n

<command>: add, set or replace

<key>: Cache name

<flag>: 16-bit unsigned integer stored with the data to be stored by key and returned when the program get s cached.

<exptime>: Past time, 0 means never expired, if not zero, unix time or the number of seconds away

<bytes>: The number of bytes in which data is stored

\ r\n: Represents a change of lanes

Orders:

STORED: Success

NOT_STORED: Failure

a) Add caching

  1. add id 1 0 4  
  2. 1234  
  3. STORED  

If the key already exists, the addition fails.

b) Modify the cache

  1. replace id 1 0 4  
  2. 3456  
  3. STORED  

     key In existence, success; in nonexistence, failure.

c),Set cache

  1. set id 1 0 4  
  2. 2345  
  3. STORED  

When the key does not exist, add it; when it already exists, replace it.

 

II. Read

Command format: get <key>+rn

<key>+: Indicates one or more keys, separated by spaces.

A) Cache to read a single key

  1. get id  
  2. VALUE id 1 4  
  3. 1234  
  4. END  

 

 b),Read multiple key Caching

  1. get id name  
  2. VALUE id 1 4  
  3. 3456  
  4. VALUE name 1 3  
  5. jim  
  6. END  

 

III, delete

Command format: delete <key>rn

<key>: the key to be deleted

Delete id

  1. delete id   
  2. DELETED  

 

IV. Clear all caches

Command format: flush_all

  1. flush_all  
  2. OK  

 

Ⅴ,Viewing Cache Server Status

//Command: stats

  1. stats  
  2. STAT pid 2711     //Process id
  3. STAT uptime 2453  //Total running time, unit description
  4. STAT time 1344856333  //Current time
  5. STAT version 1.4.0 //Version
  6. STAT pointer_size 32    //Server pointer digits, the general 32-bit operating system is 32.
  7. STAT rusage_user 0.002999  //Cumulative user time for processes
  8. STAT rusage_system 1.277805  //Cumulative system events of processes
  9. STAT curr_connections 1  //Current number of connections
  10. STAT total_connections 11  //Total number of connections after server startup
  11. STAT connection_structures 11  //Number of Connection Structures
  12. STAT cmd_get 17   //Total acquisition times
  13. STAT cmd_set 1  //Total write times
  14. STAT cmd_flush 1   //Total clearance times
  15. STAT get_hits 1  //Total number of hits
  16. STAT get_misses 7   //Get the number of misses.
  17. STAT delete_misses //Delete the number of misses.
  18. STAT delete_hits 4   //Delete hit times
  19. STAT incr_misses //Incremental operation has no hit times.
  20. STAT incr_hits //Increase the number of hit operations
  21. STAT decr_misses //Decreasing the number of times an operation missed a hit
  22. STAT decr_hits //Decrease the number of hit operations
  23. STAT cas_misses //cas Settings No Hits
  24. STAT cas_hits //cas hit times
  25. STAT cas_badval //The cas operation found the key, but the version expired and was not set successfully.
  26. STAT bytes_read 455    //Total data acquisition
  27. STAT bytes_written 1175  //Total amount of written data
  28. STAT limit_maxbytes 1048576  //Maximum allowable memory per byte.
  29. STAT accepting_conns 1      
  30. STAT listen_disabled_num 0  
  31. STAT threads 5   //Number of current threads
  32. STAT conn_yields 0  
  33. STAT bytes 56      //Used cache space
  34. STAT curr_items 1  //Number of keyvalue s currently cached
  35. STAT total_items 7 //Total number of keyvalue s cached, including expired deletions
  36. STAT evictions //The number of times memory is released by deleting keyvalue.
  37. END  

Ⅵ,Print version

//Command:version

  1. version  
  2. VERSION 1.4.0  

_. Print memory information

Command: stats slabs

  1. stats slabs  
  2. STAT 1:chunk_size 80  
  3. STAT 1:chunks_per_page 13107  
  4. STAT 1:total_pages 1  
  5. STAT 1:total_chunks 13107  
  6. STAT 1:used_chunks 1  
  7. STAT 1:free_chunks 1  
  8. STAT 1:free_chunks_end 13105  
  9. STAT 1:get_hits 10  
  10. STAT 1:cmd_set 10  
  11. STAT 1:delete_hits 4  
  12. STAT 1:incr_hits 0  
  13. STAT 1:decr_hits 0  
  14. STAT 1:cas_hits 0  
  15. STAT 1:cas_badval 0  
  16. STAT active_slabs 1  
  17. STAT total_malloced 1048560  
  18. END  

 

3. Exit telnet

  1. quit  

Posted by Ricklord on Sat, 30 Mar 2019 22:54:29 -0700