ServerInfoV26xTest.php 8.1 KB

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