ServerInfoTest.php 7.4 KB

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