memcache vs memcached
Info&Features | pecl/memcache | pecl/memcached |
---|---|---|
First Release Date | 2004-06-08 | 2009-01-29 (beta) |
Actively Developed? | Yes | Yes |
External Dependency | None | libmemcached |
Automatic Key Fixup1 | Yes | No |
Append/Prepend | No | Yes |
Automatic Serialzation2 | Yes | Yes |
Binary Protocol | No | Optional |
CAS | No | Yes |
Compression | Yes | Yes |
Communication Timeout | Connect Only | Various Options |
Consistent Hashing | Yes | Yes |
Delayed Get | No | Yes |
Multi-Get | Yes | Yes |
Session Support | Yes | Yes |
Set/Get to a specific server | No | Yes |
Stores Numerics | Converted to Strings | Yes |
- memcached是比较新的扩展,比memcache支持了更多的memcached协议
- memcache官方扩展不支持PHP7,升级PHP7后只能用memcached扩展
Note that the Memcache 3.0.8 module DOES NOT WORK WITH PHP 7 (or higher)
- memcached支持igbinary序列化,它将php的数据结构 存储为紧密的二进制形式,在时间和空间上都有所改进。
- 其他参照上面表格
PHP7升级memcached遇到的问题
因为memcache官方扩展不支持php7,所以要升级memcached扩展,但是升级过程中遇到了一些问题,请升级的小朋友注意。
memcache和memcached数据不兼容
User Contributed Notes: GOTCHA: Recently I was tasked with moving from PECL memcache to PECL memcached and ran into a major problem — memcache and memcached serialize data differently, meaning that data written with one library can’t necessarily be read with the other library.
根据实测,用memcache扩展存储的数据用memcached读不出来,比如array和object。该问题有两种解决方法:
- 直接搭建新的memcached机器,修改配置指向新的memcache机器,这意味着原来的缓存全部失效,方法简单,但是要评估失效后的DB压力
- 用老扩展memcache读取数据,然后用新扩展memcached写入数据,提前做预热,但是需要停服
经过提前预演失效对db的影响(比如说失效一定比例进行评估),我们采用了第一种方式
PHP5环境下memcached扩展OPT_LIBKETAMA_COMPATIBLE慎用
由于官方建议,设置了OPT_LIBKETAMA_COMPATIBLE为true
Note:
如果你要使用一致性hash算法强烈建议开启此选项,并且这个选项可能在未来的发布版中被设置为默认开启。
但是addServers添加的服务器过多(大概10多个以上),就会出现crash。在社区提了issue,但是一直没有回复。最终把这个字段设置为false规避解决。
Be First to Comment