InfoV24x.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Predis\Commands;
  3. class InfoV24x extends Command {
  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. $current[$k] = $v;
  22. }
  23. else {
  24. $db = array();
  25. foreach (explode(',', $v) as $dbvar) {
  26. list($dbvk, $dbvv) = explode('=', $dbvar);
  27. $db[trim($dbvk)] = $dbvv;
  28. }
  29. $current[$k] = $db;
  30. }
  31. }
  32. return $info;
  33. }
  34. }