- function _check_for_error(&$s) {
- if (!$s || $s[0] != '-')
- return;
- if (substr($s, 0, 4) == '-ERR')
- trigger_error("Redis error: " . trim(substr($s, 4)), E_USER_ERROR);
- trigger_error("Redis error: " . substr(trim($this->_read()), 5), E_USER_ERROR);
- }
-
- function &_simple_response() {
- $s =& trim($this->_read());
- if ($s[0] == '+')
- return substr($s, 1);
- if ($err =& $this->_check_for_error($s))
- return $err;
- trigger_error("Cannot parse first line '$s' for a simple response", E_USER_ERROR);
- }
-
- function &_numeric_response($allow_negative=True) {
- $s =& trim($this->_read());
- $i = (int)$s;
- if ($i . '' == $s) {
- if (!$allow_negative && $i < 0)
- $this->_check_for_error($s);
- return $i;
+ private function get_response() {
+ $data = trim($this->read());
+ $c = $data[0];
+ $data = substr($data, 1);
+ switch ($c) {
+ case '-':
+ trigger_error($data, E_USER_ERROR);
+ break;
+ case '+':
+ return $data;
+ case ':':
+ $i = strpos($data, '.') !== false ? (int)$data : (float)$data;
+ if ((string)$i != $data)
+ trigger_error("Cannot convert data '$c$data' to integer", E_USER_ERROR);
+ return $i;
+ case '$':
+ return $this->get_bulk_reply($c . $data);
+ case '*':
+ $num = (int)$data;
+ if ((string)$num != $data)
+ trigger_error("Cannot convert multi-response header '$data' to integer", E_USER_ERROR);
+ $result = array();
+ for ($i=0; $i<$num; $i++)
+ $result[] =& $this->get_response();
+ return $result;
+ default:
+ trigger_error("Invalid reply type byte: '$c'");