InfoV24x.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Predis\Commands;
  3. class InfoV24x extends Info {
  4. public function canBeHashed() { return false; }
  5. public function getId() { return 'INFO'; }
  6. public function parseResponse($data) {
  7. $info = array();
  8. $current = null;
  9. $infoLines = explode("\r\n", $data, -1);
  10. foreach ($infoLines as $row) {
  11. if ($row === '') {
  12. continue;
  13. }
  14. if (preg_match('/^# (\w+)$/', $row, $matches)) {
  15. $info[$matches[1]] = array();
  16. $current = &$info[$matches[1]];
  17. continue;
  18. }
  19. list($k, $v) = explode(':', $row);
  20. if (!preg_match('/^db\d+$/', $k)) {
  21. if ($k === 'allocation_stats') {
  22. $current[$k] = $this->parseAllocationStats($v);
  23. continue;
  24. }
  25. $current[$k] = $v;
  26. }
  27. else {
  28. $db = array();
  29. foreach (explode(',', $v) as $dbvar) {
  30. list($dbvk, $dbvv) = explode('=', $dbvar);
  31. $db[trim($dbvk)] = $dbvv;
  32. }
  33. $current[$k] = $db;
  34. }
  35. }
  36. return $info;
  37. }
  38. }