duanchu3376 2012-12-17 10:40
浏览 114
已采纳

pylibmc存储的数据无法在php memcached中解压缩

We have an application where we are using python to store lots of data in memcached.We are using pylibmc in python and on php side we are using php-memcached library.As a summary

  • pylibmc v.1.2.3
  • php-memcached v.2.0.1
  • libmemcached v1.0.8.

Everything else is fine except when compression comes into play. This is how data is compressed in 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)

checking in telnet we see some garbled value, which means it was compressed. Now reading it in php.

$memd = new Memcached();
$memd->addServer('10.90.15.104', 11211);
echo $memd->get('foo');

When above is run, we get same garbled value, which means it is not getting uncompressed. pylibmc is using zlib, so accordingly I have changed php's compression type to zlib also. What other setting needs to be done? Please help.

For further reference here are the memcached's output after setting the string in python pylibmc

get foo
VALUE foo 8 40
x+��,V�D��Ē��"����t�⒢̼t=���g\5#
END

And here's memcached's output for string stored using PHP's memcached client:

get foo
VALUE foo 48 44
�x�+��,V�D��Ē��"����t�⒢̼t=���g\5#
END

As you can see there's something fishy in this. Compressed size in pylibmc is 40 bytes and the same data compressed using php-memcached is of 44 bytes. Also notice the flags as 8 when stored using pylibmc and 48 when stored using php-memcached !

  • 写回答

2条回答 默认 最新

  • duandingqi9442 2012-12-17 15:41
    关注

    i think what you observe is due to the fact that memcache itself does not implement compression so each library does it in their own way, just compare the flags used to indicate compression is in use

    as defined by pylibmc

    #define PYLIBMC_FLAG_ZLIB (1 << 3) (so this is flag == 8)

    and by php-memcached

    #define MEMC_VAL_COMPRESSED (1<<4)

    #define MEMC_VAL_COMPRESSION_ZLIB (1<<5)

    #define MEMC_VAL_COMPRESSION_FASTLZ (1<<6)

    so i think unless you are willing to modify one of this libraries to make it's flags consistent with the other then there is no way out

    Edit: Ok, so here is the little patch that bring compression support for pylibmc and php-memcached in sync. See my github fork of pylibmc.

    Big fat warring - it works only on strings, so if you want to store objects you MUST do de/serialization on your own (JSON).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装