Detailed description of telnet connection to memcache server, telnetmemcache
As an excellent out-of-process cache, memcache is often used in high-concurrency system architecture. Here we will talk about how to use the telnet tool to view the running status of memcache and manage and maintain its key. Assume that the memcache installation directory is/usr/local/memcached.
1. Start memcache
Copy codeThe Code is as follows:
[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. pid
Detailed description of startup parameters
-D: start as a daemon. If this parameter is not specified, memcache is automatically disabled when the command ctrl + c is executed.
-M: the maximum number of memory units allocated to memcache is m. The default value is 64 m.
-U: Specifies the user who runs memcache.
-L: IP address of the listener
-P: Specifies the tcp port number of the listener. You can use-u to specify the udp port. The default value is 11211.
-C: Maximum number of concurrent connections
-P: file with the error process id
After memcache is started, we can connect to memcache through telnet for simple operation management.
2. telnet to memcache
Copy codeThe Code is as follows:
[Root @ localhost ~] # Telnet 192.168.119.70 12000
Trying 192.168.119.70...
Connected to 192.168.119.70 (192.168.119.70 ).
Escape character is '^]'.
After successful connection, you can manage memcache operations. Common Commands include:
I. Add and modify
Command syntax: <command> <key> <flags> <exptime> <bytes> \ r \ n <data block> \ r \ n
<Command>: add, set, or replace
<Key>: cache name
<Flag>: A 16-bit unsigned integer, which is stored together with the data to be stored by the key and returned when the program get caches the data.
<Exptime>: the past time. 0 indicates that it never expires. If it is not zero, it indicates the unix time or the number of seconds later.
<Bytes>: number of bytes of data stored
\ R \ n: line feed and carriage return
Command result:
STORED: indicates successful
NOT_STORED: indicates an error occurred.
A) Add Cache
Copy codeThe Code is as follows:
Add id 1 0 4
1234
STORED
If the key already exists, the addition fails.
B) modify Cache
Copy codeThe Code is as follows:
Replace id 1 0 4
3456
STORED
If the key exists, it is successful. If the key does not exist, it fails.
C) Set Cache
Copy codeThe Code is as follows:
Set id 1 0 4
2345
STORED
If the key does not exist, add [add]; if the key already exists, replace [replace ].
Ii. Read
Command Format: get <key> + \ r \ n
<Key> +: indicates one or more keys. Separate multiple keys with spaces.
A) read the cache of a single key
Copy codeThe Code is as follows:
Get id
VALUE id 1 4
1234
END
B) read the cache of multiple keys
Copy codeThe Code is as follows:
Get id name
VALUE id 1 4
3456
VALUE name 1 3
Jim
END
Iii. Delete
Command Format: delete <key> \ r \ n
<Key>: key to be deleted
Delete id
Copy codeThe Code is as follows:
Delete id
DELETED
Iv. Clear all caches
Command Format: flush_all
Copy codeThe Code is as follows:
Flush_all
OK
V. view the Cache Server Status
Command: stats
Copy codeThe Code is as follows:
Stats
STAT pid 2711 // process id
STAT uptime 2453 // total running time, unit description
STAT time 1344856333 // current time
STAT version 1.4.0 // version
STAT pointer_size 32 // Number of server pointer digits. Generally, the 32-bit operating system is 32
STAT rusage_user 0.002999 // cumulative user time of the process
STAT rusage_system 1.277805 // accumulative System Event of the process
STAT curr_connections 1 // current number of connections
STAT total_connections 11 // total number of connections after the server is started
STAT connection_structures 11 // Number of connection structures
STAT cmd_get 17 // total number of times of obtaining
STAT cmd_set 1 // total number of writes
STAT cmd_flush 1 // total number of cleanups
STAT get_hits 1 // total number of hits
STAT get_misses 7 // gets no hits
STAT delete_misses // number of times no hits are deleted
STAT delete_hits 4 // Number of Delete hits
STAT incr_misses // No hits during incremental operations
STAT incr_hits // increase the number of Operation hits
STAT decr_misses // The number of times the specified operation has not been hit
STAT decr_hits // decrease the number of hits
STAT cas_misses // set no hits
STAT cas_hits // cas hits
STAT cas_badval // The key is found in the cas operation, but the version has expired and is not set successfully.
STAT bytes_read 455 // obtain the total data volume
STAT bytes_written 1175 // Total write data volume
STAT limit_maxbytes 1048576 // maximum memory usage, in bytes
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 5 // current thread count
STAT conn_yields 0
STAT bytes 56 // used cache space
STAT curr_items 1 // number of currently cached keyvalues
STAT total_items 7 // total number of cached keyvalues, including expired deleted
STAT evictions // number of times the memory is released by deleting the keyvalue
END
Vi. Print version
Command: version
Copy codeThe Code is as follows:
Version
VERSION 1.4.0
VII. Print memory information
Command: stats slabs
Copy codeThe Code is as follows:
Stats slabs
STAT 1: chunk_size 80
STAT 1: chunks_per_page 13107
STAT 1: total_pages 1
STAT 1: total_chunks 13107
STAT 1: used_chunks 1
STAT 1: free_chunks 1
STAT 1: free_chunks_end 13105
STAT 1: get_hits 10
STAT 1: performance_set 10
STAT 1: delete_hits 4
STAT 1: incr_hits 0
STAT 1: decr_hits 0
STAT 1: cas_hits 0
STAT 1: cas_badval 0
STAT active_slabs 1
STAT total_malloced 1048560
END
3. Exit telnet
Copy codeThe Code is as follows:
Quit
Complete!