Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use multi(Redis::PIPELINE) with RedisArray #251

Closed
ericparent opened this issue Sep 20, 2012 · 2 comments
Closed

How to use multi(Redis::PIPELINE) with RedisArray #251

ericparent opened this issue Sep 20, 2012 · 2 comments

Comments

@ericparent
Copy link

Basically using this in my code:

//$redis is a RedisArray here

$key = 'hello';

$host = $redis->_target($key);
$pipeline = $redis->multi($host, Redis::PIPELINE);

//put result in our shared list
foreach ($items as $item)
{
$pipeline->sAdd($key, $item);
}

$ret = $pipeline->exec();

The problem here is I have no clue if this is actually using PIPELINE or MULTI, and the documentation doesn't really specify how to use RedisArray multi with pipelining.

If anyone could confirm that I am using it correctly, I would really appreciate it.

Cheers

@michael-grunder
Copy link
Member

Hey,

You look to be calling it correctly from where I'm sitting. The only way (without stepping into phpredis code itself) to see if a pipeline is being used would be to compare the performance of using one and not using one. When you're using a pipeline you should see faster execution times.

You can see if MULTI/EXEC is happening by monitoring Redis. This simple script allows you to either pass an argument or not (which will toggle Redis::PIPELINE or Redis::MULTI). When you do MULTI you can see it in your redis-cli monitor output.

When you toggle to use Redis::MULTI the performance will be slower as well. Other than that the only thing I can say is that the code for pipeline and multi calls the same methods, and just switches based on the type being called.

    if(isset($argv[1])) {
        $mode = Redis::MULTI;
        $m_str = 'MULTI';
    } else {
        $mode = Redis::PIPELINE;
        $m_str = 'PIPELINE';
    }

    $st = microtime(true);

    $r = new RedisArray(Array("localhost:6390", "localhost:6391"));

    for($i=0;$i<100;$i++) {
        $set = "set$i";
        $host = $r->_target($set);
        echo $host . "\n";

        $pipe = $r->multi($host, $mode);

        for($j=0;$j<100;$j++) {
            $pipe->sadd($set, "value$j");
        }

        $pipe->exec();
    }

    $et = microtime(true);

    echo "Timing ($m_str): " . ($et-$st) . "\n";

@ericparent
Copy link
Author

Confirm that I am using it correctly. Using michael-grunder's script, I have the following benchmarks:

with Redis::MULTI

0.41849994659424 secs

with Redis::PIPELINE

0.084672927856445 secs

It would be great if the RedisArray readme file mentioned how to toggle the mode for multi()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants