Skip to content

Instantly share code, notes, and snippets.

@h2ero
Created July 24, 2013 07:03
Show Gist options
  • Save h2ero/6068579 to your computer and use it in GitHub Desktop.
Save h2ero/6068579 to your computer and use it in GitHub Desktop.
<?php
/**
* PHP gen redis protocol function
* author: h2ero <122750707@qq.com>
* date: 2013-07-24 15:01:42
* useage: php gen_redis_proto.php | redis-cli --pipe
*/
function gen_redis_proto()
{
$CRLF = "\r\n";
$args = func_get_args();
$proto = '*'.count($args).$CRLF;
foreach ($args as $arg) {
$proto .= '$'.strlen($arg).$CRLF;
$proto .= $arg.$CRLF;
}
return $proto;
}
for ($i = 0; $i < 1000000; $i++) {
echo gen_redis_proto("SET", "MYKEY$i", "VALUE$i");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment