Redis是一个TCP服务器,支持请求/响应协议。 在Redis中,请求经过如下步骤完成:php
若是须要一次执行多个redis命令,以往的方式须要发送屡次命令请求,有redis服务器依次执行,并返回结果,redis
为了解决此类问题,设计者设计出了redis管道命令:服务器
作了测试,使用pipeline的时长为603.4ms,不使用则为10716.9ms,差距有18倍之多!性能
如下是代码:测试
<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\Redis; class LessonsController extends Controller { public function showProfile() { $this->G('t'); // redis::pipeline(); for ($i=0; $i < 100000 ; $i++) { redis::set("test_{$i}", pow($i, 2)); redis::get('test_{$i}'); } redis::exec(); $this->G('t','r'); } public function G($start,$end='',$dec=4) { static $_info = array(); if (!empty($end)) { if(!isset($_info[$end])) $_info[$end] = microtime(TRUE); $sconds = number_format(($_info[$end]-$_info[$start]), $dec) * 1000; echo "{$sconds}ms<br />"; } else { $_info[$start] = microtime(TRUE); } } }