123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- require 'SharedConfigurations.php';
- use Predis\ConnectionParameters;
- use Predis\Commands\ICommand;
- use Predis\Network\StreamConnection;
- class SimpleDebuggableConnection extends StreamConnection {
- private $_debugBuffer = array();
- private $_tstart = 0;
- public function connect() {
- $this->_tstart = microtime(true);
- parent::connect();
- }
- private function storeDebug(ICommand $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 writeCommand(ICommand $command) {
- parent::writeCommand($command);
- $this->storeDebug($command, '->');
- }
- public function readResponse(ICommand $command) {
- $reply = parent::readResponse($command);
- $this->storeDebug($command, '<-');
- return $reply;
- }
- public function getDebugBuffer() {
- return $this->_debugBuffer;
- }
- }
- $options = array(
- 'connections' => array(
- 'tcp' => 'SimpleDebuggableConnection',
- ),
- );
- $redis = new Predis\Client($single_server, $options);
- $redis->set('foo', 'bar');
- $redis->get('foo');
- $redis->info();
- print_r($redis->getConnection()->getDebugBuffer());
|