ServerInfoV26x.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 = explode("\r\n", $data, -1);
  25. foreach ($infoLines as $row) {
  26. if ($row === '') {
  27. continue;
  28. }
  29. if (preg_match('/^# (\w+)$/', $row, $matches)) {
  30. $info[$matches[1]] = array();
  31. $current = &$info[$matches[1]];
  32. continue;
  33. }
  34. list($k, $v) = explode(':', $row);
  35. if (!preg_match('/^db\d+$/', $k)) {
  36. if ($k === 'allocation_stats') {
  37. $current[$k] = $this->parseAllocationStats($v);
  38. continue;
  39. }
  40. $current[$k] = $v;
  41. }
  42. else {
  43. $current[$k] = $this->parseDatabaseStats($v);
  44. }
  45. }
  46. return $info;
  47. }
  48. }