- 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;
+ function &get_response() {
+ $data = trim($this->_read());
+ $c = $data[0];
+ $data = substr($data, 1);
+ switch ($c) {
+ case '-':
+ trigger_error(substr($data, 0, 4) == 'ERR ' ? substr($data, 4) : $data, E_USER_ERROR);
+ break;
+ case '+':
+ return $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_value();
+ return $result;
+ default:
+ return $this->_get_value($c . $data);