Memcache and Telnent Command detailed

Source: Internet
Author: User
Tags memcached

1, start memcache common parameters
Memcached 1.4.3
-P <num> Set port number (default is not set to: 11211)
-U <num> UDP Listening port (default: 11211, 0 o'clock off)
-L <ip_addr> Bind address (default: All allowed, regardless of internal or external network or local replacement IP, there is a security risk, if set to 127.0.0.1 can only be native access)
-D Duli Process runs
-U <username> bindings use specified for running processes <username>
-M <num> allowable maximum memory usage, Unit m (default: MB)
-P <file> writes the PID to the file <file&gt, which enables fast process termination behind and needs to be used with-D
Such as:
Under Linux:./usr/local/bin/memcached-d-U jb-mc-l 192.168.1.197-m 2048-p 12121
Under window: d:\App_Serv\memcached\memcached.exe-d runservice-l 127.0.0.1-p 11211-m 500
Run after registering as a service under Windows:
Sc.exe Create jb-memcached binpath= "d:\App_Serv\memcached\memcached.exe-d runservice-p 11211-m 500″start= Auto
net start jb-memcached

2. Telnet connection

Telnet 127.0.0.1 11211

3. Write Memcache

3.1 memcached Telnet Interface

Command Description Example
Get Reads a value Get MyKey
Set Set a key unconditionally Set MyKey 0 60 5
Add ADD a new key Add Newkey 0 60 5
Replace Overwrite existing Key Replace key 0 60 5
Append Append data to existing key Append key 0 60 15
Prepend Prepend data to existing key Prepend Key 0 60 15
incr Increments numerical key value by given number INCR MyKey 2
Decr Decrements numerical key value by given number DECR MyKey 5
Delete Deletes an existing key Delete MyKey
Flush_all Invalidate specific items immediately Flush_all
Invalidate all items in n seconds Flush_all 900
Stats Prints General Statistics Stats
Prints Memory Statistics Stats Slabs
Prints Memory Statistics Stats malloc
Print Higher level allocation statistics Stats items
Stats Detail
Stats sizes
Resets statistics Stats Reset
Version Prints Server version. Version
Verbosity Increases log level Verbosity
Quit Terminate Telnet session Quit

3.2 Telnet Request command format

<command name> <key> <flags> <exptime> <bytes>\r\n <data block>\r\n
A) <command name> can be "set", "Add", "replace".
"Set" means that the data is stored in accordance with the corresponding <key>, there is no time to increase, some overwrite.
"Add" means that the data is added according to the appropriate <key>, but the operation fails if the <key> already exists.
"Replace" means that the data is replaced by the appropriate <key>, but the operation fails if the <key> does not exist

b) <key> the client needs to save the data key.

c) <flags> is a 16-bit unsigned integer (expressed in decimal notation).
The flag is stored along with the data that needs to be stored and is returned when the client get data.
Customers can use this flag for special purposes and this flag is opaque to the server.

D) The time of <exptime> expires.
A 0 indicates that the stored data is never obsolete (but can be replaced by the server algorithm: LRU, etc.).
If it is not 0 (Unix time or the number of seconds in the distance), when it expires, the server can guarantee that the user will not get the data (server time is the standard).

e) <bytes> the number of bytes that need to be stored (not including the last "\ r \ n"),,<bytes> can be 0 when the user wants to store empty data

f) The final client needs to add "\ r \ n" As the end flag for the "command header".
<data block>\r\n

Immediately after the "command header" to send the data block (that is, the data content you want to store), and finally add "\ r \ n" As the end of this communication.

3.3 Telnet Response command

Result response: Reply
When the above data is sent, the server returns an answer. The following may be the case:

A) "stored\r\n": Indicates storage success
b) "not_stored\r\n": Indicates that the store failed, but the failure was not due to an error.
This is usually caused by the requirement of the "add" or "replace" command itself, or the item is in the delete queue.

Example: Set key 0 4\r\n
ffff\r\n

4. Get/Check KeyValue
Get <key>*\r\n
A) <key>* denotes one or more keys (separated by a space)
b) End of "\ r \ n" Command header

Result response: Reply
The server side will return 0 or more data items. Each data item consists of a line of text and a block of data. When all data items are received, you will receive "end\r\n"
Data structures for each item:
VALUE <key> <flags> <bytes>\r\n
<data block>\r\n

A) <key> want to get the key to store the data
b) <falg> flag item set when sending the set command
c) <bytes> the length of the sending data block (not including "\ r \ n")
d) "\ r \ n" Text line end flag
e) <data block> The data item that you want to receive.
f) "\ r \ n" Receives the end sign of a data item.

If some keys appear on the GET command line but do not return the corresponding data, this means that these items do not exist on the server, they are obsolete, or are deleted
such as: Get AA
VALUE AA 33 4
Ffff
END

5. Delete KeyValue:
Delete <key> <time>\r\n

A) <key> key to delete data
b) The time that the <time> client wants the server to delete the data (Unix time or the number of seconds from now)
c) End of "\ r \ n" Command header

6. Check the Memcache server status:
stats\r\n
Here you can see the number of memcache, the current number of connections, the number of writes, has been hit rate, etc.

PID: Process ID
Uptime: Total elapsed time, number of seconds
Time: Current
Version: Revision number
......
Curr_items: Number of keyvalue in the current cache
Total_items: Number of keyvalue that have been cached in total
Bytes: Amount of memory used by all caches
Curr_connections Current number of connections
....
Cmd_get: Total number of fetches
Cmd_set: Total number of writes
Get_hits: Total number of hits
Miss_hits: Gets the number of failures
.....
Bytes_read: Total bytes of traffic read
Bytes_written: Total bytes of write traffic
Limit_maxbytes: Maximum allowable amount of memory, bytes

7, Advanced Cache Details View method:
Stats Reset
Clear statistics

Stats malloc
Display memory allocation data

Stats Cachedump slab_id Limit_num
Displays a list of the first limit_num keys in a slab, shown in the following format
ITEM Key_name [Value_length b; expire_time|access_time S]
where memcached 1.2.2 and previous versions show the access Time (timestamp)
1.2.4 above, including 1.2.4 Display expiration Time (timestamp)
If the key,expire_time is never expired, it will be displayed as the server startup time

Stats Cachedump 7 2
ITEM Copy_test1 [+ b; 1207795754 S]
ITEM Copy_test [248 b; 1207793649 S]

Stats Slabs
Displays information about each slab, including the size, number, usage, etc. of the chunk

Stats items
Displays the number of item in each slab and the age of the oldest item (the number of seconds the last access distance is now)

Stats detail [On|off|dump]
Set or display detailed operation Records

parameter is on to open detailed operation record
parameter is off, close verbose operation record
The parameter is dump, showing the detailed operation record (number of times each key value get, set, hit, Del)

8. Clear all Key values
Flush_all
Note: Flush does not delete items, except that all items are marked as expired, so Memcache still occupies all of the memory.

9. Exit
quit\r\n

Memcache and Telnent Command detailed

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.