在 php 的 memcached 中为单个 set() 调用设置压缩标志的最佳方法是什么?
我正在从 memcache 迁移到 memcached 我注意到的差异之一是压缩标志似乎是为 all set()
调用,而不是像 memcache
那样基于个体进行调用。
这是每个连接的设置,还是我可以打开和关闭它?如果是后者,为每个 set()
调用设置压缩标志的最佳方法是什么?
目前我正在考虑做这样的事情:
<?php
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,true);
$return = $mc->set($key,$object,$expiration);
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,false);
这是正确的方法吗?
我也像这样设置 $mc
,如果有什么区别:
<?php
$mc = new Memcached("cl");
$mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
if (count($mc->getServerList()) === 0) {
$mc->addServers(array (
array ($GLOBALS["mc"]["host"],$GLOBALS["mc"]["port"]),
));
}
谢谢!
I'm migrating from memcache to memcached and one of the differences I've noticed is that the compression flag seems to be set for all set()
calls, not on an individual basis like with memcache
.
Is this a per-connection setting, or can I toggle this on and off? If it's the latter, what would be the best way to go about setting the compression flag for each set()
call?
Currently I'm thinking of doing something like this:
<?php
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,true);
$return = $mc->set($key,$object,$expiration);
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,false);
Is this the right approach?
I'm also setting up $mc
like this, if it makes any difference:
<?php
$mc = new Memcached("cl");
$mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
if (count($mc->getServerList()) === 0) {
$mc->addServers(array (
array ($GLOBALS["mc"]["host"],$GLOBALS["mc"]["port"]),
));
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下两个 方法 并且还阅读了Memcached的源代码,我认为不可能为每个
设置它设置。
请参阅 github 上的 php-memcached-dev,查找
php_memcached.c
(顺便说一句,对于客户端来说这是一个多么愚蠢的名称。Memcached 过去意味着服务器守护进程,现在它是意味着服务器和客户端,你不能再用谷歌搜索它了。)
Taking a look at the signature of the two methods and also reading the source of Memcached, I think it is not possible to set it for each
set
.See php-memcached-dev on github, look for
php_memcached.c
(What a stupid name for the client by the way. Memcached used to mean the server daemon, now it means server and client, you just can't google it any more.)