Under Telnet operation Memcache Detailed explanation (Operation order Detailed) _ Database other

Source: Internet
Author: User

When locating problems, testing, and so on, often need to do some operations on the memcache data, but it does not have its own client, so only through telnet to operate.

Connect memcache by Telnet.

Copy Code code as follows:

Telnet 127.0.0.1 11211

Memcache Write operations

Telnet write memcache command format

Copy Code code as follows:

<command name> <key> <flags> <exptime> <bytes>\r\n <data block>\r\n

Parameter detailed:

1.<command name> can be "set", "Add", "replace".

Overwrite if set:<key> is not present when adding,<key> exists.
When a add:<key> does not exist, it fails to add a,<key> existence.
Add failure when replace:<key> does not exist,<key> replace data when present

2.<key> Key to save data

The 3.<flags> is a 16-bit unsigned integer (expressed in decimal notation).

The flag is stored with the data that needs to be stored and returned when the client get data.
Customers can use this flag for special purposes, which is transparent to the server.

4.<exptime> the expiration time.

0 indicates that the stored data is never obsolete (but can be replaced by the server algorithm: LRU, etc.).
Non-0 (Unix time), when expired, the server can ensure that the user does not get the data (in the server time standard).

5.<bytes> the number of bytes that need to be stored (without the last "\ \ \ \ \ \ \ \ \ \ \ \"), when the user wants to store empty data, can be 0

6. The final client needs to add "\ r \ n" As the end sign of the "command header".

7.<data block>\r\n

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


Telnet response command

When the above data is sent over, the server returns a reply. The following may be the case:

1.stored\r\n: Indicates storage success

2.not_stored\r\n: Indicates that the store failed, but the failure was not due to an error.
> Usually this is caused by the requirement of the "add" or "replace" command itself, or the item is in the delete queue.

Example

Copy Code code as follows:

Set key 0 10\r\n
helloworld\r\n
stored\r\n

Get Key&value

Get command format

Copy Code code as follows:

Get <key>*\r\n

Parameter detailed:
1.<key>*: Represents one or more key (separated by spaces)
2.\r\n: End of command

Response results

The server side will return 0 or more data items. Each data item is made up of a line of text and a block of data. When all items are received, the data structure of each item is received end\r\n:

Copy Code code as follows:

VALUE <key> <flags> <bytes>\r\n
<data block>\r\n

Parameter detailed:
1.<key> want to get key to store data
2.<falg> the flag item that is set when the SET command is sent
3.<bytes> the length of the data block to send (does not contain "\ r \ n")
4.\r\n Text line End flag
5.<data block> The data item that you want to receive.
6.\r\n receives the end flag of a data item.

PS: If some keys appear in the Get command line but do not return the corresponding data, this means that there is no change in the server, may be timed out, or deleted.

Example

Copy Code code as follows:

Get key
VALUE Key 32 10
HelloWorld
End

Delete KeyValue:

Copy Code code as follows:
Delete <key> <time>\r\n

Parameter detailed:
1.<key> the key that needs to be deleted data
2.<time> the time that the client expects the server to delete the data (Unix time or the number of seconds from now)
End of 3.\r\n command header

Check memcache Server Status

Copy Code code as follows:
stats\r\n

Here you can see the number of memcache, the current number of connections, write times, has been hit, etc.

Copy Code code as follows:

PID: Process ID
Uptime: Total elapsed time, number of seconds
Time: Current times
Version: Edition number
......
Curr_items: Number of keyvalue in current cache
Total_items: Number of keyvalue that have been cached in total
Bytes: The amount of memory used by all caches
Curr_connections Number of current connections
....
Cmd_get: Total acquisition times
Cmd_set: Total number of writes
Get_hits: Total Hit count
Miss_hits: Get failed Count
.....
Bytes_read: bytes of traffic read in total
Bytes_written: Total Write traffic bytes
Limit_maxbytes: Maximum allowable amount of memory, bytes

To clear the statistical data:

Copy Code code as follows:

Stats Reset

Empty all key values

Copy Code code as follows:

Flush_all

Note: Flush does not delete items, except that all items are marked as expired, so memcache still occupies all memory.

Exit

Copy Code code as follows:

quit\r\n


Other commands

1. Display information on various slab, including chunk size, number, usage, etc.

Copy Code code as follows:
Stats Slabs

2. Show the number of item in each slab and the age of the oldest item (last access is now the number of seconds)

Copy Code code as follows:
Stats items

3. Set or display detailed operation Records

Copy Code code as follows:
Stats detail [On|off|dump]

parameter is on, open detailed action record
parameter is off, close detailed operation record
parameter is dump, showing detailed operation records (number of times per key-value get, set, hit, Del)

4. Display the first Limit_num key list in a slab

Copy Code code as follows:
Stats Cachedump slab_id Limit_num

The display format is as follows:
Copy Code code as follows:
ITEM <key_name> [<value_length> b; <expire_time|access_time> S]

<key_name>: Key Name
<value_length>: Value Length (unit bytes)
<expire_time|access_time>:memcached 1.2.2 and previous versions show the access Time (timestamp)

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.