memcached frequently used commands and instructions _php tutorials

Source: Internet
Author: User
Format of the stored command:


The parameters are described as follows:
Set/add/replace
Find keywords
The client uses it to store extra information about key-value pairs
The survival time of this data, 0 means forever
Number of bytes stored
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 performed the stats cachedump 1 0 command effect as follows: Here slab_id is 1, which is determined by the result returned by the stats items in 2 (the number following the STAT items); Limit_num looks like it's going to return how many records, guess it's a good one, However, 0 indicates that all records are displayed, 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
In the existing cache dataafterAdding cached data, such as an existing cache key, does not exist for the server response as not_stored.

2, Prepend
and append very similar, but its role is in the existing cache databeforeAdd cached data.
3, Flush_allThe 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.

Add: A simple understanding of several caches in the. NET Framework
The importance of caching in a Web site is beyond doubt. I think many ASP. NET developers prefer to use a cache that is not a third-party caching solution (such as distributed cache memcached, Redis, and so on) when developing Web applications, but should be a variety of caching solutions already available in the. Network framework. Let's talk about the understanding of caching in the. NET Framework in the context of your own development experience.

1, System.Web.Caching.Cache
It is estimated that most of the people who have done the ASP have used the cache under this namespace, and we can use the HttpContext.Current.Cache instance directly without instantiating it. Of course, the cache class under this namespace allows you to instantiate, and of course you can completely control how to initialize this class by customizing your own caching system. I've seen a lot of articles in the garden. The CRUD auxiliary class libraries that introduce the Cache are mostly for System.Web.Caching.Cache.

It should be explained that we can also use the Httpruntime.cache under this namespace to implement caches in different representations of the Web, console, WinForm, and so on, without having to instantiate them at all. Httpruntime.cache is one of the more used classes in personal development, and now prefers the enhanced cache class MemoryCache in. NET framework4.0.

2. Output Cache
As we all know, output cache is mainly paged out cache and page partial cache. Plainly, is to cache the entire page of HTML or part of the HTML, there is nothing worth discussing, but recently saw Dudu this blog just suddenly discovered, unexpectedly use it is really very fastidious, I did not find this problem before? It seems that the ability to find and solve problems is equally important, and sometimes the former is even more important.

3, System.Runtime.Caching
Now the most used class memorycache in personal development is derived from this namespace, and the using System.Runtime.Caching is required before use. MemoryCache inherits from ObjectCache, IEnumerable, IDisposable, where ObjectCache is an abstract class. People who have used MemoryCache know that this memorycache has a property called default, which can usually be used as follows:

private static ObjectCache MemCache = Memorycache.default; Of course, we can also fully pass public memorycache (string name, NameValueCollection config = null) constructor initializes the cache object.

Then we can configure the memory usage quota scheme and the quota check cycle for each MemoryCache instance running in the Web. config file, the following example references MSDN:
Copy the Code code as follows:








These configuration implications lie in the ability to explicitly specify the memory usage quota scheme and the quota check cycle that each MemoryCache instance runs. For example, we can configure to change the memory quota of the Memorycache.default instance on demand (not knowing how much memory is available for the cache, perhaps the legendary 800M or so). The cache expiration policy is much the same as its cache framework, unlike System.Web.Caching.Cache, whose name is not cachedependency but called ChangeMonitor, and provides a file-and directory-based cache dependency policy. The cache expiration policy is also more important to explore, but in personal development more emphasis on data caching and replacement, there is no contact and use of a more perfect expiration policy solution.

http://www.bkjia.com/PHPjc/327884.html www.bkjia.com true http://www.bkjia.com/PHPjc/327884.html techarticle format of stored commands: command name Key flags Exptime bytes The data block parameter is described as follows: command name set/add/replace key Find keyword flags client uses it to store About Keys ...

  • 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.