ServerInfoV26x.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Commands;
  11. /**
  12. * @link http://redis.io/commands/info
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class ServerInfoV26x extends ServerInfo
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function parseResponse($data)
  21. {
  22. $info = array();
  23. $current = null;
  24. $infoLines = preg_split('/\r?\n/', $data);
  25. if (isset($infoLines[0]) && $infoLines[0][0] !== '#') {
  26. return parent::parseResponse($data);
  27. }
  28. foreach ($infoLines as $row) {
  29. if ($row === '') {
  30. continue;
  31. }
  32. if (preg_match('/^# (\w+)$/', $row, $matches)) {
  33. $info[$matches[1]] = array();
  34. $current = &$info[$matches[1]];
  35. continue;
  36. }
  37. list($k, $v) = explode(':', $row);
  38. if (!preg_match('/^db\d+$/', $k)) {
  39. if ($k === 'allocation_stats') {
  40. $current[$k] = $this->parseAllocationStats($v);
  41. continue;
  42. }
  43. $current[$k] = $v;
  44. }
  45. else {
  46. $current[$k] = $this->parseDatabaseStats($v);
  47. }
  48. }
  49. return $info;
  50. }
  51. }