One, storage command
Format of the stored command:
12 |
<command name> <key> <flags> <exptime> <bytes> <data block> |
The parameters are described as follows:
<command name> |
Set/add/replace |
<key> |
Find keywords |
<flags> |
The client uses it to store extra information about key-value pairs |
<exptime> |
The survival time of this data, 0 means forever |
<bytes> |
Number of bytes stored |
<data block> |
Stored data blocks (can be directly understood as value in the key-value structure) |
1. Add
(1), the set that is stored anyway
This set command is used very frequently in memcached. The set command can not only be added simply, if the set key already exists, the command can update the key corresponding to the original data, that is, to achieve the role of the update.
You can view the added records in the form of "Get Key Name":
As you know, we can also remove the Delete command and add it again.
(2), add only when data does not exist
(3) Replace when the data is present
2. Delete
As you can see, deleting a key value that already exists and a record that does not exist can return different results.
Second, read command 1, get
The key of the GET command can represent one or more keys, separated by a space
2, gets
As you can see, the GET command returns a number (medium 13) More than the normal gets command. This number checks to see if the data has changed. When the data corresponding to the key changes, the number returned will also change.
3. CAs
CAS is the meaning of checked and set, which can only be stored if the last parameter matches the parameters obtained by the GET, otherwise "EXISTS" is returned.
Iii. Status Command 1, stats
2. Stats items
Perform stats items, you can see the stat items row, and if memcached stores a lot of content, there will also be a lot of stat items listed here.
3, stats cachedump slab_id limit_num
We perform the stats cachedump 1 0 command effect as follows:
The slab_id here is 1, which is determined by the results returned by the stats items in 2 (the number following the STAT items); Limit_num looks like it's going to return as many records as it's worth, but 0 means it shows all the records, and N (n>0) Indicates that N records are displayed, and if n exceeds all records under the slab, the result is the same as the result returned by 0.
Limit_num records can be traversed by stats items, stats cachedump slab_id memcached with the Get command.
4. Other Stats commands
such as stats slabs,stats sizes,stats Reset, etc. use is also more common.
Iv. Other common commands 1, append
Add the cached data after the existing cache data, such as the existing cache key does not exist for the server response as not_stored.
2, Prepend
is very similar to append, but it is useful for adding cached data before existing cache data.
3, Flush_all
The command has an optional numeric parameter. It always executes successfully and the server sends a "ok\r\n" response. The effect is to invalidate an existing project immediately (the default), or after a specified time. After that the FETCH command is executed and nothing is returned (unless the same key name is re-stored). Flush_all actually does not immediately release the memory occupied by the project, but is executed later when new items are stored (this is determined by memcached's lazy detection and deletion mechanism).
The Flush_all effect is that it causes all items to be updated earlier than the time set by Flush_all, and the command is ignored when the FETCH command is executed.
4. Other commands
Memcached also has a lot of commands, such as the storage of digital type can be used by the INCR/DECR command to increase or decrease operations, and so on, here only the development and operation of the regular use of commands, the other no longer one by one examples.
Principle:
Caching policies
When the MS Hash table is full, the new insert data replaces the old data, and the updated strategy is the LRU (least recently used) and the effective time limit for each kv pair. The KV-to-store effective time limit is set in the MC driven by app and passed as a parameter to Ms.
While Ms Adoption is a lazy alternative, MS does not open an additional process to monitor the outdated kv pairs and delete them in real time, but only if and when the new data is inserted, and there is no extra space left to remove the action.
Reprint finishing http://www.cnblogs.com/jeffwongishandsome/archive/2011/11/06/2238265.html.
Memcached Common Commands and principles