INFO_Test.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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\Command\Redis;
  11. /**
  12. * @group commands
  13. * @group realm-server
  14. */
  15. class INFO_Test extends PredisCommandTestCase
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getExpectedCommand()
  21. {
  22. return 'Predis\Command\Redis\INFO';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function getExpectedId()
  28. {
  29. return 'INFO';
  30. }
  31. /**
  32. * @group disconnected
  33. */
  34. public function testFilterArguments()
  35. {
  36. $command = $this->getCommand();
  37. $command->setArguments(array());
  38. $this->assertSame(array(), $command->getArguments());
  39. }
  40. /**
  41. * @group disconnected
  42. */
  43. public function testCanParseNewResponseFormat()
  44. {
  45. $raw = <<<BUFFER
  46. # Server
  47. redis_version:2.9.0
  48. redis_git_sha1:237194b7
  49. redis_git_dirty:0
  50. arch_bits:32
  51. multiplexing_api:epoll
  52. process_id:16620
  53. tcp_port:6379
  54. uptime_in_seconds:444
  55. uptime_in_days:0
  56. lru_clock:198040
  57. # Clients
  58. connected_clients:1
  59. client_longest_output_list:0
  60. client_biggest_input_buf:0
  61. blocked_clients:0
  62. # Memory
  63. used_memory:628076
  64. used_memory_human:613.36K
  65. used_memory_rss:1568768
  66. used_memory_peak:570056
  67. used_memory_peak_human:556.70K
  68. used_memory_lua:14336
  69. mem_fragmentation_ratio:2.50
  70. mem_allocator:jemalloc-2.2.1
  71. # Persistence
  72. loading:0
  73. aof_enabled:0
  74. changes_since_last_save:0
  75. bgsave_in_progress:0
  76. last_save_time:1323185719
  77. bgrewriteaof_in_progress:0
  78. # Stats
  79. total_connections_received:4
  80. total_commands_processed:3
  81. rejected_connections:0
  82. expired_keys:0
  83. evicted_keys:0
  84. keyspace_hits:0
  85. keyspace_misses:0
  86. pubsub_channels:0
  87. pubsub_patterns:0
  88. latest_fork_usec:0
  89. # Replication
  90. role:master
  91. connected_slaves:0
  92. # CPU
  93. used_cpu_sys:0.06
  94. used_cpu_user:0.06
  95. used_cpu_sys_children:0.00
  96. used_cpu_user_children:0.00
  97. # Cluster
  98. cluster_enabled:0
  99. # Keyspace
  100. db0:keys=2,expires=0
  101. db5:keys=1,expires=0
  102. BUFFER;
  103. $expected = array(
  104. 'Server' => array(
  105. 'redis_version' => '2.9.0',
  106. 'redis_git_sha1' => '237194b7',
  107. 'redis_git_dirty' => '0',
  108. 'arch_bits' => '32',
  109. 'multiplexing_api' => 'epoll',
  110. 'process_id' => '16620',
  111. 'tcp_port' => '6379',
  112. 'uptime_in_seconds' => '444',
  113. 'uptime_in_days' => '0',
  114. 'lru_clock' => '198040',
  115. ),
  116. 'Clients' => array(
  117. 'connected_clients' => '1',
  118. 'client_longest_output_list' => '0',
  119. 'client_biggest_input_buf' => '0',
  120. 'blocked_clients' => '0',
  121. ),
  122. 'Memory' => array(
  123. 'used_memory' => '628076',
  124. 'used_memory_human' => '613.36K',
  125. 'used_memory_rss' => '1568768',
  126. 'used_memory_peak' => '570056',
  127. 'used_memory_peak_human' => '556.70K',
  128. 'used_memory_lua' => '14336',
  129. 'mem_fragmentation_ratio' => '2.50',
  130. 'mem_allocator' => 'jemalloc-2.2.1',
  131. ),
  132. 'Persistence' => array(
  133. 'loading' => '0',
  134. 'aof_enabled' => '0',
  135. 'changes_since_last_save' => '0',
  136. 'bgsave_in_progress' => '0',
  137. 'last_save_time' => '1323185719',
  138. 'bgrewriteaof_in_progress' => '0',
  139. ),
  140. 'Stats' => array(
  141. 'total_connections_received' => '4',
  142. 'total_commands_processed' => '3',
  143. 'rejected_connections' => '0',
  144. 'expired_keys' => '0',
  145. 'evicted_keys' => '0',
  146. 'keyspace_hits' => '0',
  147. 'keyspace_misses' => '0',
  148. 'pubsub_channels' => '0',
  149. 'pubsub_patterns' => '0',
  150. 'latest_fork_usec' => '0',
  151. ),
  152. 'Replication' => array(
  153. 'role' => 'master',
  154. 'connected_slaves' => '0',
  155. ),
  156. 'CPU' => array(
  157. 'used_cpu_sys' => '0.06',
  158. 'used_cpu_user' => '0.06',
  159. 'used_cpu_sys_children' => '0.00',
  160. 'used_cpu_user_children' => '0.00',
  161. ),
  162. 'Cluster' => array(
  163. 'cluster_enabled' => '0',
  164. ),
  165. 'Keyspace' => array(
  166. 'db0' => array('keys' => '2', 'expires' => '0'),
  167. 'db5' => array('keys' => '1', 'expires' => '0'),
  168. ),
  169. );
  170. $this->assertSame($expected, $this->getCommand()->parseResponse($raw));
  171. }
  172. /**
  173. * @group disconnected
  174. */
  175. public function testCanParseOldResponsesFormat()
  176. {
  177. $raw = <<<BUFFER
  178. redis_version:2.4.4
  179. redis_git_sha1:bc62bc5e
  180. redis_git_dirty:0
  181. arch_bits:32
  182. multiplexing_api:epoll
  183. process_id:15640
  184. uptime_in_seconds:792
  185. uptime_in_days:0
  186. lru_clock:197890
  187. used_cpu_sys:0.08
  188. used_cpu_user:0.10
  189. used_cpu_sys_children:0.00
  190. used_cpu_user_children:0.00
  191. connected_clients:1
  192. connected_slaves:0
  193. client_longest_output_list:0
  194. client_biggest_input_buf:0
  195. blocked_clients:0
  196. used_memory:556156
  197. used_memory_human:543.12K
  198. used_memory_rss:1396736
  199. used_memory_peak:547688
  200. used_memory_peak_human:534.85K
  201. mem_fragmentation_ratio:2.51
  202. mem_allocator:jemalloc-2.2.1
  203. loading:0
  204. aof_enabled:0
  205. changes_since_last_save:0
  206. bgsave_in_progress:0
  207. last_save_time:1323183872
  208. bgrewriteaof_in_progress:0
  209. total_connections_received:2
  210. total_commands_processed:1
  211. expired_keys:0
  212. evicted_keys:0
  213. keyspace_hits:0
  214. keyspace_misses:0
  215. pubsub_channels:0
  216. pubsub_patterns:0
  217. latest_fork_usec:0
  218. vm_enabled:0
  219. role:master
  220. db0:keys=2,expires=0
  221. db5:keys=1,expires=0
  222. BUFFER;
  223. $expected = array(
  224. 'redis_version' => '2.4.4',
  225. 'redis_git_sha1' => 'bc62bc5e',
  226. 'redis_git_dirty' => '0',
  227. 'arch_bits' => '32',
  228. 'multiplexing_api' => 'epoll',
  229. 'process_id' => '15640',
  230. 'uptime_in_seconds' => '792',
  231. 'uptime_in_days' => '0',
  232. 'lru_clock' => '197890',
  233. 'used_cpu_sys' => '0.08',
  234. 'used_cpu_user' => '0.10',
  235. 'used_cpu_sys_children' => '0.00',
  236. 'used_cpu_user_children' => '0.00',
  237. 'connected_clients' => '1',
  238. 'connected_slaves' => '0',
  239. 'client_longest_output_list' => '0',
  240. 'client_biggest_input_buf' => '0',
  241. 'blocked_clients' => '0',
  242. 'used_memory' => '556156',
  243. 'used_memory_human' => '543.12K',
  244. 'used_memory_rss' => '1396736',
  245. 'used_memory_peak' => '547688',
  246. 'used_memory_peak_human' => '534.85K',
  247. 'mem_fragmentation_ratio' => '2.51',
  248. 'mem_allocator' => 'jemalloc-2.2.1',
  249. 'loading' => '0',
  250. 'aof_enabled' => '0',
  251. 'changes_since_last_save' => '0',
  252. 'bgsave_in_progress' => '0',
  253. 'last_save_time' => '1323183872',
  254. 'bgrewriteaof_in_progress' => '0',
  255. 'total_connections_received' => '2',
  256. 'total_commands_processed' => '1',
  257. 'expired_keys' => '0',
  258. 'evicted_keys' => '0',
  259. 'keyspace_hits' => '0',
  260. 'keyspace_misses' => '0',
  261. 'pubsub_channels' => '0',
  262. 'pubsub_patterns' => '0',
  263. 'latest_fork_usec' => '0',
  264. 'vm_enabled' => '0',
  265. 'role' => 'master',
  266. 'db0' => array('keys' => '2', 'expires' => '0'),
  267. 'db5' => array('keys' => '1', 'expires' => '0'),
  268. );
  269. $this->assertSame($expected, $this->getCommand()->parseResponse($raw));
  270. }
  271. /**
  272. * @group disconnected
  273. */
  274. public function testDoesNotEmitPhpNoticeOnEmptyResponse()
  275. {
  276. $this->assertSame(array(), $this->getCommand()->parseResponse(''));
  277. }
  278. /**
  279. * @group connected
  280. * @requiresRedisVersion >= 2.6.0
  281. */
  282. public function testReturnsAnArrayOfInfo()
  283. {
  284. $redis = $this->getClient();
  285. $command = $this->getCommand();
  286. $this->assertInternalType('array', $info = $redis->executeCommand($command));
  287. $this->assertArrayHasKey('redis_version', isset($info['Server']) ? $info['Server'] : $info);
  288. }
  289. /**
  290. * @group connected
  291. * @requiresRedisVersion < 2.6.0
  292. */
  293. public function testReturnsAnArrayOfInfoOnOlderRedisVersions()
  294. {
  295. $redis = $this->getClient();
  296. $command = $this->getCommand();
  297. $this->assertInternalType('array', $info = $redis->executeCommand($command));
  298. $this->assertArrayHasKey('redis_version', $info);
  299. }
  300. }