1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- require __DIR__.'/shared.php';
- use Predis\Command\CommandInterface;
- use Predis\Connection\StreamConnection;
- class SimpleDebuggableConnection extends StreamConnection
- {
- private $tstart = 0;
- private $debugBuffer = array();
- public function connect()
- {
- $this->tstart = microtime(true);
- parent::connect();
- }
- private function storeDebug(CommandInterface $command, $direction)
- {
- $firtsArg = $command->getArgument(0);
- $timestamp = round(microtime(true) - $this->tstart, 4);
- $debug = $command->getId();
- $debug .= isset($firtsArg) ? " $firtsArg " : ' ';
- $debug .= "$direction $this";
- $debug .= " [{$timestamp}s]";
- $this->debugBuffer[] = $debug;
- }
- public function writeRequest(CommandInterface $command)
- {
- parent::writeRequest($command);
- $this->storeDebug($command, '->');
- }
- public function readResponse(CommandInterface $command)
- {
- $response = parent::readResponse($command);
- $this->storeDebug($command, '<-');
- return $response;
- }
- public function getDebugBuffer()
- {
- return $this->debugBuffer;
- }
- }
- $options = array(
- 'connections' => array(
- 'tcp' => 'SimpleDebuggableConnection',
- ),
- );
- $client = new Predis\Client($single_server, $options);
- $client->set('foo', 'bar');
- $client->get('foo');
- $client->info();
- var_export($client->getConnection()->getDebugBuffer());
|