数据查询用了memcache缓存,用sql做的键值,传递分页的参数 sql就会产生变化 如果没有数据 就会重新查询并缓存 但是现在遇到这样一个问题 我在本地测试没有问题 但是传到服务器以后 无论传递什么参数 sql 是随之变化的 但是依据变化的键值 获得的数据列表并不跟着变化 请教一下大家可能是什么原因
回复讨论(解决方案) 怎??
如果你?的是一?字符串,不可能?的,?查下代?。
看看是否?自?加上那些。
是不是服务器数据就那么几条 不用分页啊? 导致每页数据都一样。。
贴出关键代码。
怎??
如果你?的是一?字符串,不可能?的,?查下代?。
看看是否?自?加上那些。
我把整个查询的sql 作为键值来存储数据的 刚开始上传到服务器的时候是没问题的读取正常也没有分页重复 ,运行一段时间后发现重复,后来同事说可能是因为把整个sql作为键值太长 md5($sql) 以后 再作为键值传递就正常了 ,memcache 缓存 会因为键值太长影响数据读取吗?
贴出关键代码。
$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); }
每次查询根据条件产生的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搞起吧。
谢谢大家的热心回答