Memcache cache is used for data query, and the key value of SQL is used, and the paging data remains unchanged.

Source: Internet
Author: User
Tags control characters what parameter
Apsaradb for memcache is used for data query, while apsaradb for memcache is used for data query on different pages. apsaradb for memcache is used for data query, passing the paging parameter SQL will change. if there is no data, it will be re-queried and cached. but now there is such a problem. I have no problem in local testing, but after passing it to the server, no matter what parameter SQL is passed the data list obtained based on the changed key value does not change accordingly.


Reply to discussion (solution)

How ????
If you? Is one? String, not possible? ,? Check the next generation ?.
Check whether? ? Add ?? Those ??.

Isn't there just a few pieces of server data without paging? The data on each page is the same ..

Paste the key code.

How ????
If you? Is one? String, not possible? ,? Check the next generation ?.
Check whether? ? Add ?? Those ??.

I used the queried SQL statement as the key value to store data. When I first uploaded the data to the server, it was okay to read the data normally and there were no duplicate pages, later, my colleague said that it may be because the entire SQL statement is too long to be passed as a key value after md5 ($ SQL, does memcache cache affect data reading because the key value is too long?

Paste the key code.


$sql = "select id,avg_point,name,xpoint,ypoint,agent_area_id,area_id,supplier_id,index_img,dp_count,avg_point,deal_cate_id,ratio,area_id,note from aa  where 1 = 1 and is_effect=1 and city_id in (18,1) order by id DESC limit 0,15"; $key =  $GLOBALS['append_config']['IOS_CACHE_PRE'].$sql;    $info = mcache_get($key); if(!$info){    $info = $GLOBALS['db']->getAll($sql);    mcache_set($key,$info); }
Each query generates different SQL statements based on different conditions. as long as the SQL statements are different, they are retrieved again. However, even if the SQL statements are different as key values, data is not retrieved again.

Set $ SQL md5? Let's take a look.
What are memcache keys? .

$ SQL = "select id, avg_point, name, xpoint, ypoint, agent_area_id, area_id, supplier_id, index_img, dp_count, avg_point, deal_cate_id, ratio, area_id, note from aa where 1 = 1 and is_effect = 1 and city_id in () order by id DESC limit ";
$ Key = md5 ($ GLOBALS ['append _ config'] ['iOS _ CACHE_PRE ']. $ SQL );
$ Info = mcache_get ($ key );
If (! $ Info ){
$ Info = $ GLOBALS ['DB']-> getAll ($ SQL );
Mcache_set ($ key, $ info );
}

Isn't there just a few pieces of server data without paging? The data on each page is the same ..

Many of the data requires paging.

Keys
----

Data stored by memcached is identified with the help of a key. A key
Is a text string which shoshould uniquely identify the data for clients
That are interested in storing and retrieving it. Currently
Length limit of a key is set at 250 characters (of course, normally
Clients wouldn't need to use such long keys); the key must not include
Control characters or whitespace.

Baidu translation:
Data is stored in memcached and identified by key values. One-key
Is a text string that must uniquely identify customer data
Storage and Retrieval. Currently,
The maximum length of a key IS 250 characters (of course, usually
The customer does not need to use a long key.
Control characters or spaces.

Apparently, you have already violated the rules.

Ls has clearly stated that although your SQL statement is about 220 characters long, it does not exceed the maximum character limit of memcached. However, because SQL contains spaces, the part before the first space of SQL is actually used as the key. in this case, it is clear that all paging data is the same.
Let's start with MD5.

Thank you for your enthusiastic answers.

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.