Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate memcache in telnet

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about how to operate memcache in telnet, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Connect to the memcache through telnet.

The copy code is as follows:

Telnet 127.0.0.1 11211

Memcache write operation

Telnet write memcache command format

The copy code is as follows:

\ r\ n\ r\ n

Detailed description of parameters:

1. It can be "set", "add", "replace".

Set: add when it does not exist, overwrite when it exists.

Add: add if it does not exist, but the operation will fail if it exists.

Replace: failed to add if it does not exist, and replace data if it exists

two。 Key that saves the data

3. Is a 16-bit unsigned integer (expressed in decimal).

This flag will be stored with the data that needs to be stored and returned when the client-side get data.

Customers can use this logo for special purposes, and this flag is transparent to the server.

4. The expiration time.

0 means that the stored data is never out of date (but can be replaced by server algorithms: LRU, etc.).

Non-0 (unix time), when expired, the server can guarantee that the data will not be available to the user (based on server time).

5. The number of bytes to be stored (excluding the last "\ r\ n"), which can be 0 when the user wants to store empty data

6. Finally, the client needs to add "\ r\ n" as the end flag of the "command header".

7.\ r\ n

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

Telnet responds to command

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

1.STORED\ r\ n: indicates successful storage

2.NOT_STORED\ r\ n: indicates a storage failure, but the failure is not due to an error.

Usually this is caused by the request of the "add" or "replace" command itself, or the item is in the delete queue.

Example

The copy code is as follows:

Set key 32 0 10\ r\ n

Helloworld\ r\ n

STORED\ r\ n

Get Key&Value

Get command format

The copy code is as follows:

Get *\ r\ n

Detailed description of parameters:

1. Blank: indicates one or more key (separated by spaces)

2.\ r\ n: command ends

Response result

The server will return 0 or more data items. Each data item consists of a line of text and a block of data. When all the data items have been received, you will receive the END\ r\ ndata structure of each item:

The copy code is as follows:

VALUE\ r\ n

\ r\ n

Detailed description of parameters:

1. Want to get the key where the data is stored

two。 Flag entry set when sending the set command

3. Length of the sent block (does not contain "\ r\ n")

4.\ r\ nThe end flag of the text line

5. The data item you want to receive.

6.\ r\ nreceive the end flag of a data item.

PS: if some key appears on the get command line but does not return the corresponding data, it means that there are no changes in the server, maybe it has timed out, or it has been deleted.

Example

The copy code is as follows:

Get key

VALUE key 32 10

Helloworld

END

Delete KeyValue:

The copy code is as follows:

Delete\ r\ n

Detailed description of parameters:

1. Key that needs to be deleted

two。 The time the client wants the server to delete the data (unix time or seconds from now)

3.\ r\ nThe end of the command header

Check Memcache server status

The copy code is as follows:

Stats\ r\ n

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

The copy code is as follows:

Pid: process id

Uptime: total elapsed time, seconds

Time: current Tim

Version: version number

……

Curr_items: the number of KeyValue in the current cache

Total_items: total number of KeyValue that have been cached

Bytes: the amount of memory used by all caches

Current number of connections to curr_connections

... .

Cmd_get: total number of times obtained

Cmd_set: total number of writes

Get_hits: total number of hits

Miss_hits: get the number of failures

... ..

Bytes_read: total number of traffic bytes read

Bytes_written: total write traffic bytes

Limit_maxbytes: the maximum amount of memory allowed, in bytes

Clear statistics:

The copy code is as follows:

Stats reset

Clear all key values

The copy code is as follows:

Flush_all

Note: flush does not delete items, but marks all items as expired, so memcache still takes up all memory.

Quit

The copy code is as follows:

Quit\ r\ n

Other commands

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

The copy code is as follows:

Stats slabs

two。 Displays the number of item in each slab and the age of the oldest item (seconds from the last visit)

The copy code is as follows:

Stats items

3. Set or display detailed operation records

The copy code is as follows:

Stats detail [on | off | dump]

Parameter is on, and open the detailed operation record

Parameter is off to close the detailed operation record

The parameter is dump, which displays the detailed operation record (the number of times of each key value get, set, hit, del)

4. Displays a list of the previous limit_num key in a slab

The copy code is as follows:

Stats cachedump slab_id limit_num

The display format is as follows:

The copy code is as follows:

ITEM [b; s]

Key name

Value length (in bytes)

Memcached 1.2.2 and previous versions show access time (timestamp)

The above is how to operate memcache in telnet. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report