Sha256: d61aa6d0594dfd1830401856807177f498c771c515fe7ccf0f42b46a5684bbe4
Contents?: true
Size: 1.64 KB
Versions: 7
Compression:
Stored size: 1.64 KB
Contents
<?php namespace Predis\Commands; class ServerInfo extends Command { public function getId() { return 'INFO'; } protected function onPrefixKeys(Array $arguments, $prefix) { /* NOOP */ } protected function canBeHashed() { return false; } public function parseResponse($data) { $info = array(); $infoLines = explode("\r\n", $data, -1); foreach ($infoLines as $row) { @list($k, $v) = explode(':', $row); if ($row === '' || !isset($v)) { continue; } if (!preg_match('/^db\d+$/', $k)) { if ($k === 'allocation_stats') { $info[$k] = $this->parseAllocationStats($v); continue; } $info[$k] = $v; } else { $info[$k] = $this->parseDatabaseStats($v); } } return $info; } protected function parseDatabaseStats($str) { $db = array(); foreach (explode(',', $str) as $dbvar) { list($dbvk, $dbvv) = explode('=', $dbvar); $db[trim($dbvk)] = $dbvv; } return $db; } protected function parseAllocationStats($str) { $stats = array(); foreach (explode(',', $str) as $kv) { @list($size, $objects, $extra) = explode('=', $kv); // hack to prevent incorrect values when parsing the >=256 key if (isset($extra)) { $size = ">=$objects"; $objects = $extra; } $stats[$size] = $objects; } return $stats; } }
Version data entries
7 entries across 7 versions & 1 rubygems