【发布时间】:2012-12-17 10:40:55
【问题描述】:
我们有一个应用程序,我们使用 python 在 memcached 中存储大量数据。我们在 python 中使用 pylibmc,在 php 端,我们使用 php-memcached 库。总结
- pylibmc v.1.2.3
- php-memcached v.2.0.1
- libmemcached v1.0.8。
除了压缩发挥作用外,其他一切都很好。这就是python中数据的压缩方式
import pylibmc
mem = pylibmc.Client(['10.90.15.104:11211'], binary=True)
mem.set('foo','this is a rather long string. this is a rather '+
'long string. this is a rather long string. this is a rather' +
'long string. this is a rather long string', 0, 10)
在 telnet 中检查我们看到一些乱码值,这意味着它被压缩了。现在用 php 读取它。
$memd = new Memcached();
$memd->addServer('10.90.15.104', 11211);
echo $memd->get('foo');
当上面运行时,我们得到相同的乱码值,这意味着它没有被解压缩。 pylibmc 正在使用 zlib,因此我也将 php 的压缩类型更改为 zlib。还需要做什么设置?请帮忙。
为了进一步参考,这里是在 python pylibmc 中设置字符串后 memcached 的输出
get foo
VALUE foo 8 40
x+��,V�D��Ē��"����t�⒢̼t=���g\5#
END
这是使用 PHP 的 memcached 客户端存储的字符串的 memcached 输出:
get foo
VALUE foo 48 44
�x�+��,V�D��Ē��"����t�⒢̼t=���g\5#
END
如您所见,这其中有些可疑之处。 pylibmc 中的压缩大小为 40 字节,使用 php-memcached 压缩的相同数据为 44 字节。另请注意,使用 pylibmc 存储时标志为 8,使用 php-memcached 存储时标志为 48!
【问题讨论】:
标签: php python memcached zlib libmemcached