<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/mysql_memcached_space/</link>
<title><![CDATA[当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[Cache与存储]]></category>
<pubDate>Tue, 06 Jul 2010 10:42:28 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/</guid> 
<description>
<![CDATA[ 
	　　同事下午遇到一问题，MySQL 和 Memcached 对于同一个key，不能对应起来。最终原因是：PHP将key写入MySQL数据库之前，没有经过trim()过滤首尾空格（关键是尾部空格），结果：<br/><br/>　　1、MySQL的varchar、char类型字段，SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中，存储的含有尾部空格的内容“rewinx ”，通过以下三种方式均可查询到：<br/><br/>　　<a href="http://zyan.cc/attachment/201007/mysqlspace.png" target="_blank"><img src="http://zyan.cc/attachment/201007/mysqlspace.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道（<a href="http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char" target="_blank">http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char</a>）：请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此，并且它不受SQL服务器模式的影响。<br/><br/><hr/><br/>　　2、PHP 的 Memcache 扩展，则在set、get时，自动将key中的空格，转换成了半角下划线“_”。当然，直接通过 Memcached 协议来读取，key值“rewinx ”就要写成“rewinx_”了。<br/><br/>............<br/><br/>Tags - <a href="http://zyan.cc/tags/mysql/" rel="tag">mysql</a> , <a href="http://zyan.cc/tags/memcached/" rel="tag">memcached</a> , <a href="http://zyan.cc/tags/memcache/" rel="tag">memcache</a> , <a href="http://zyan.cc/tags/php/" rel="tag">php</a> , <a href="http://zyan.cc/tags/space/" rel="tag">space</a> , <a href="http://zyan.cc/tags/varchar/" rel="tag">varchar</a> , <a href="http://zyan.cc/tags/char/" rel="tag">char</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6302</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>ll &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 06 Jul 2010 12:57:30 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6302</guid> 
<description>
<![CDATA[ 
	问一下如果数据库是实时更新新闻之类的，用memcached合适不？那memcached也不是要经常更新，缓存还有意义吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6308</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>Kth007 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 Jul 2010 00:03:20 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6308</guid> 
<description>
<![CDATA[ 
	好像是,又学到了。
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6311</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>kaka &lt;dinghwy@126.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 Jul 2010 04:05:23 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6311</guid> 
<description>
<![CDATA[ 
	php中这类问题还真不少，对所有的字符串数据，最好都是trim之后再用。
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6312</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>shiny &lt;shiny@meettea.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 Jul 2010 07:35:40 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6312</guid> 
<description>
<![CDATA[ 
	学习之。
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6313</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>翠星石 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 Jul 2010 08:34:19 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6313</guid> 
<description>
<![CDATA[ 
	嗯，以后会注意这个问题，谢谢张宴老师
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6314</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>xiaoyu &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 Jul 2010 08:42:14 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6314</guid> 
<description>
<![CDATA[ 
	php中 &#039;&nbsp;&nbsp;111&nbsp;&nbsp;&#039; == &#039;111&#039;
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6317</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>PHPer.yang &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 08 Jul 2010 01:30:21 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6317</guid> 
<description>
<![CDATA[ 
	如果有两个key呢，一个key是_，一个key是空格,怎么取？
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6318</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>littlehz &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 08 Jul 2010 02:40:14 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6318</guid> 
<description>
<![CDATA[ 
	我们的项目中，所有key-value存储的key都是md5散列的，这样在分服务器部署也比较平均。md5慢的话可以考虑下base64应该也还不错。
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6324</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>吕滔 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 09 Jul 2010 01:18:01 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6324</guid> 
<description>
<![CDATA[ 
	这个挺有用<br/><br/>哈
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6326</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>apmserv &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 09 Jul 2010 06:04:37 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6326</guid> 
<description>
<![CDATA[ 
	期待您的apmserv更新！！！！
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6330</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>双色球 &lt;gigididi@sina.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 09 Jul 2010 15:20:30 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6330</guid> 
<description>
<![CDATA[ 
	围观围观
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6345</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>猫哥 &lt;yigenangua09@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 13 Jul 2010 01:11:59 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6345</guid> 
<description>
<![CDATA[ 
	php还不太了解。
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6354</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>张老师 &lt;1000@t.omcom&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 14 Jul 2010 10:36:46 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6354</guid> 
<description>
<![CDATA[ 
	长老师，你是弄啥的阿
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6388</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>求知者 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 20 Jul 2010 06:16:06 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6388</guid> 
<description>
<![CDATA[ 
	张宴老师，问您一个问题，我服务器使用的是apache，墓前网站最近几天httpd进程非常多，以至于打不开网站了都，请问这个是什么问题呢？
]]>
</description>
</item><item>
<link>http://zyan.cc/mysql_memcached_space/#blogcomment6407</link>
<title><![CDATA[[评论] 当 MySQL 和 Memcached 遇到尾部空格时]]></title> 
<author>手机侦探 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 23 Jul 2010 04:33:02 +0000</pubDate> 
<guid>http://zyan.cc/mysql_memcached_space/#blogcomment6407</guid> 
<description>
<![CDATA[ 
	memache键名有非0-9a-zA-Z_的字符，最好是md5后再使用。
]]>
</description>
</item>
</channel>
</rss>