今天在做一个mysql查询结果返回时,发现用查询的sql语句做memcache的key有问题,后来想了下有可能是因为key中不能包含空格吧,在网上查了一下,果然如此。所以用正则转换了一下key的内容,另外别忘了key有长度限制,最多250个字符。
代码如下:
$key = preg_replace('/\s+/','',$key);
附memcahce关于key的说明
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.

本文探讨了在MySQL查询结果返回过程中使用Memcache时遇到的问题,即查询的SQL语句作为Memcache的键可能导致的问题。文章提供了解决方案,通过正则表达式移除键中的空白字符,并提醒注意键的最大长度限制。

3455

被折叠的 条评论
为什么被折叠?



