ServerInfoTest.php 7.3 KB

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