資料查詢用了memcache緩衝,用sql做的索引值,分頁資料不變解決辦法

來源:互聯網
上載者:User
資料查詢用了memcache緩衝,用sql做的索引值,分頁資料不變
資料查詢用了memcache緩衝,用sql做的索引值,傳遞分頁的參數 sql就會產生變化 如果沒有資料 就會重新查詢並緩衝 但是現在遇到這樣一個問題 我在本地測試沒有問題 但是傳到伺服器以後 無論傳遞什麼參數 sql 是隨之變化的 但是依據變化的索引值 獲得的資料列表並不跟著變化 請教一下大家可能是什麼原因
------解決思路----------------------
把$sql md5處理吧。
memcache key有長度限制的。

$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 = md5($GLOBALS['append_config']['IOS_CACHE_PRE'].$sql);
$info = mcache_get($key);
if(!$info){
$info = $GLOBALS['db']->getAll($sql);
mcache_set($key,$info);
}
------解決思路----------------------
Keys
----

Data stored by memcached is identified with the help of a key. A key
is a text string which should uniquely identify the data for clients
that are interested in storing and retrieving it. Currently the
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.

百度翻譯:
資料存放區在memcached通過索引值來標識。一個鍵的
是一個文本字串必須唯一地識別客戶的資料
有興趣的儲存和檢索。目前,
一個鍵的長度限制是250字元(當然,通常
客戶不需要使用長鍵);鍵必須不包括
控制字元或空格。

顯然你已經違規了
------解決思路----------------------
ls已經說的很清楚了,雖然你的sql語句大約是220個字元長,並沒有超出memcached的最大字元限制。但是因為sql中含有空格,所以,實際是使用sql的第一個空格之前的部分作為key的,這樣的話,顯然所有分頁的資料都是一樣的。
還是MD5搞起吧。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.