Skip to content

Commit

Permalink
Added manual implementation for Redis::info()
Browse files Browse the repository at this point in the history
  • Loading branch information
joelcox committed May 16, 2012
1 parent 3381476 commit a7776b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libraries/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ private function _encode_request($request, $data = NULL)
}
return $request;
}

/**
* Info
*
* Overrides the default Redis response,
* so we return a nice array instead of a nasty string.
* @return array
*/
public function info()
{
$response = $this->command('INFO');
$data = array();
$pieces = explode("\r\n", $response);

// Extract the key and value
foreach ($pieces as $piece)
{
$parts = explode(':', $piece);
$data[$parts[0]] = $parts[1];
}

return $data;
}

/**
* Debug
Expand Down
10 changes: 10 additions & 0 deletions tests/Redis_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ public function test_overloading()

}

/**
* Test info
*/
public function test_info()
{
$info = $this->redis->info();
$this->assertTrue(isset($info['redis_version']));
$this->assertTrue(isset($info['process_id']));
}

}

0 comments on commit a7776b4

Please sign in to comment.