开发者

What's the best way to set the compression flag for individual set() calls in php's memcached?

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 开发者_如何学Cabout 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!


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜