multi(Redis::PIPELINE); for ($i = 0; $i < 10000; $i++) {"/> multi(Redis::PIPELINE); for ($i = 0; $i < 10000; $i++) {">

Home >Backend Development >PHP Tutorial >Redis pipeline test analysis

Redis pipeline test analysis

WBOY
WBOYOriginal
2016-07-28 08:27:071259browse

First program:

<?php
$redis = new Redis();   
$redis->connect('127.0.0.1', 6379);
$starttime = explode(" ",microtime());
$pipe = $redis->multi(Redis::PIPELINE);   
for ($i = 0; $i <  10000; $i++) {   
    $pipe->set("key::$i", str_pad($i, 4, '0', 0));   
    $pipe->get("key::$i");   
}   
      
$replies = $pipe->exec(); 
//echo " "; print_r($replies);

$endtime = explode(" ",microtime());

$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime = round($thistime,3);
echo $thistime;
echo "\r\n";

$a = array();
$starttime1 = explode(" ",microtime());
for($i= 0;$i<10000;$i++){
	$redis->set("key::$i", str_pad($i, 4, '0', 0));
}
for($i=0;$i<10000;$i++){
	array_push($a, $redis->get("key::$i"));
}

//print_r($a);
$endtime1 = explode(" ",microtime());
$thistime = $endtime1[0]+$endtime1[1]-($starttime1[0]+$starttime1[1]);
$thistime = round($thistime,3);
echo $thistime;
echo "\r\n";


Execution time statistics:

 redis的pipeline测试分析

The above introduces the pipeline test analysis of redis, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn