I would like to take advantage of client pipelining when populating database. How can I achieve this using perl Redis client?
use Redis;
my $redis = Redis->new or die "No redis server";
$redis->multi;
for my $i (1 .. 20000) {
$redis->set("key.$i" => "foo" x500);
}
$redis->exec;
The documentation says you need to add a coderef to as the third argument to set
.
To use pipelining, add a coderef argument as the last argument to a command method call
That would turn your example into:
for my $i (1 .. 20000) {
$redis->set("key.$i" => "foo" x500, sub {});
}
Instead of the empty sub, you can actually do stuff to the reply:
The coderef you supply to a pipelined command method is invoked once the response is available. It takes two arguments, $reply and $error. If $error is defined, it contains the text of an error reply sent by the Redis server. Otherwise, $reply is the non-error reply. For almost all commands, that means it's undef, or a defined but non-reference scalar, or an array ref of any of those; but see "keys", "info", and "exec".
It also says in the transaction handling part of the doc:
Warning: the behaviour of these commands when combined with pipelining is still under discussion, and you should NOT use them at the same time just now.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句