同事下午遇到一问题,MySQL 和 Memcached 对于同一个key,不能对应起来。最终原因是:PHP将key写入MySQL数据库之前,没有经过trim()过滤首尾空格(关键是尾部空格),结果:

  1、MySQL的varchar、char类型字段,SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中,存储的含有尾部空格的内容“rewinx ”,通过以下三种方式均可查询到:

  点击在新窗口中浏览此图片

  在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道(http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char):请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此,并且它不受SQL服务器模式的影响。



  2、PHP 的 Memcache 扩展,则在set、get时,自动将key中的空格,转换成了半角下划线“_”。当然,直接通过 Memcached 协议来读取,key值“rewinx ”就要写成“rewinx_”了。

  示例:testmc.php
  点击在新窗口中浏览此图片






技术大类 » Cache与存储 | 评论(46) | 引用(0) | 阅读(38084)
JoeKevin Email
2021-12-4 16:26
Games that have made many people give up because it has quite high skill requirements, are you one of them? Or will you conquer the game and make it tame before you? Experience and feel at The Impossible Game to confirm it!
paul Email
2022-11-15 17:45
As a leading e-commerce development company, we created Store24x7 that can help you in every way as soon as the orders start coming in. To enhance daily sales, we can help you regulate mobile, website, and phone orders.  Ecommerce services
john Email
2022-11-15 20:20
we provide the guaranteed value with manageable projects to our valued clients.  Web & Mobile App Development ServicesWeb & Mobile App Development Services
yojiyit888 Email Homepage
2023-6-8 12:16
Thanks for sharing all these information, it’s so appreciated! dicks price match
Lucky cola
2024-2-7 15:04
Immerse yourself in the ultimate gaming universe.  Lucky cola
分页: 3/3 第一页 上页 1 2 3 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]