KeyPrefixProcessorTest.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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\Processor;
  11. use Predis\Command\RawCommand;
  12. use PredisTestCase;
  13. /**
  14. *
  15. */
  16. class KeyPrefixProcessorTest extends PredisTestCase
  17. {
  18. /**
  19. * @group disconnected
  20. */
  21. public function testConstructorWithPrefix()
  22. {
  23. $prefix = 'prefix:';
  24. $processor = new KeyPrefixProcessor($prefix);
  25. $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $processor);
  26. $this->assertEquals($prefix, $processor->getPrefix());
  27. }
  28. /**
  29. * @group disconnected
  30. */
  31. public function testChangePrefix()
  32. {
  33. $prefix1 = 'prefix:';
  34. $prefix2 = 'prefix:new:';
  35. $processor = new KeyPrefixProcessor($prefix1);
  36. $this->assertEquals($prefix1, $processor->getPrefix());
  37. $processor->setPrefix($prefix2);
  38. $this->assertEquals($prefix2, $processor->getPrefix());
  39. }
  40. /**
  41. * @group disconnected
  42. */
  43. public function testProcessPrefixableCommandInterface()
  44. {
  45. $prefix = 'prefix:';
  46. $command = $this->getMock('Predis\Command\PrefixableCommandInterface');
  47. $command->expects($this->never())->method('getId');
  48. $command->expects($this->once())->method('prefixKeys')->with($prefix);
  49. $processor = new KeyPrefixProcessor($prefix);
  50. $processor->process($command);
  51. }
  52. /**
  53. * @group disconnected
  54. */
  55. public function testSkipNotPrefixableCommands()
  56. {
  57. $command = $this->getMock('Predis\Command\CommandInterface');
  58. $command->expects($this->once())
  59. ->method('getId')
  60. ->will($this->returnValue('unknown'));
  61. $command->expects($this->never())
  62. ->method('getArguments');
  63. $processor = new KeyPrefixProcessor('prefix');
  64. $processor->process($command);
  65. }
  66. /**
  67. * @group disconnected
  68. */
  69. public function testInstanceCanBeCastedToString()
  70. {
  71. $prefix = 'prefix:';
  72. $processor = new KeyPrefixProcessor($prefix);
  73. $this->assertEquals($prefix, (string) $processor);
  74. }
  75. /**
  76. * @group disconnected
  77. */
  78. public function testPrefixFirst()
  79. {
  80. $arguments = array('1st', '2nd', '3rd', '4th');
  81. $expected = array('prefix:1st', '2nd', '3rd', '4th');
  82. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  83. $command->setRawArguments($arguments);
  84. KeyPrefixProcessor::first($command, 'prefix:');
  85. $this->assertSame($expected, $command->getArguments());
  86. // Empty arguments
  87. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  88. KeyPrefixProcessor::skipLast($command, 'prefix:');
  89. $this->assertEmpty($command->getArguments());
  90. }
  91. /**
  92. * @group disconnected
  93. */
  94. public function testPrefixAll()
  95. {
  96. $arguments = array('1st', '2nd', '3rd', '4th');
  97. $expected = array('prefix:1st', 'prefix:2nd', 'prefix:3rd', 'prefix:4th');
  98. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  99. $command->setRawArguments($arguments);
  100. KeyPrefixProcessor::all($command, 'prefix:');
  101. $this->assertSame($expected, $command->getArguments());
  102. // Empty arguments
  103. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  104. KeyPrefixProcessor::skipLast($command, 'prefix:');
  105. $this->assertEmpty($command->getArguments());
  106. }
  107. /**
  108. * @group disconnected
  109. */
  110. public function testPrefixInterleaved()
  111. {
  112. $arguments = array('1st', '2nd', '3rd', '4th');
  113. $expected = array('prefix:1st', '2nd', 'prefix:3rd', '4th');
  114. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  115. $command->setRawArguments($arguments);
  116. KeyPrefixProcessor::interleaved($command, 'prefix:');
  117. $this->assertSame($expected, $command->getArguments());
  118. // Empty arguments
  119. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  120. KeyPrefixProcessor::skipLast($command, 'prefix:');
  121. $this->assertEmpty($command->getArguments());
  122. }
  123. /**
  124. * @group disconnected
  125. */
  126. public function testPrefixSkipLast()
  127. {
  128. $arguments = array('1st', '2nd', '3rd', '4th');
  129. $expected = array('prefix:1st', 'prefix:2nd', 'prefix:3rd', '4th');
  130. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  131. $command->setRawArguments($arguments);
  132. KeyPrefixProcessor::skipLast($command, 'prefix:');
  133. $this->assertSame($expected, $command->getArguments());
  134. // Empty arguments
  135. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  136. KeyPrefixProcessor::skipLast($command, 'prefix:');
  137. $this->assertEmpty($command->getArguments());
  138. }
  139. /**
  140. * @group disconnected
  141. */
  142. public function testPrefixSort()
  143. {
  144. $arguments = array('key', 'BY', 'by_key_*', 'STORE', 'destination_key');
  145. $expected = array('prefix:key', 'BY', 'prefix:by_key_*', 'STORE', 'prefix:destination_key');
  146. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  147. $command->setRawArguments($arguments);
  148. KeyPrefixProcessor::sort($command, 'prefix:');
  149. $this->assertSame($expected, $command->getArguments());
  150. // Empty arguments
  151. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  152. KeyPrefixProcessor::sort($command, 'prefix:');
  153. $this->assertEmpty($command->getArguments());
  154. }
  155. /**
  156. * @group disconnected
  157. */
  158. public function testPrefixZSetStore()
  159. {
  160. $arguments = array('key:destination', 2, 'key1', 'key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum');
  161. $expected = array(
  162. 'prefix:key:destination', 2, 'prefix:key1', 'prefix:key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum',
  163. );
  164. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  165. $command->setRawArguments($arguments);
  166. KeyPrefixProcessor::zsetStore($command, 'prefix:');
  167. $this->assertSame($expected, $command->getArguments());
  168. // Empty arguments
  169. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  170. KeyPrefixProcessor::zsetStore($command, 'prefix:');
  171. $this->assertEmpty($command->getArguments());
  172. }
  173. /**
  174. * @group disconnected
  175. */
  176. public function testPrefixEval()
  177. {
  178. $arguments = array('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'foo', 'hoge', 'bar', 'piyo');
  179. $expected = array(
  180. 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'prefix:foo', 'prefix:hoge', 'bar', 'piyo',
  181. );
  182. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  183. $command->setRawArguments($arguments);
  184. KeyPrefixProcessor::evalKeys($command, 'prefix:');
  185. $this->assertSame($expected, $command->getArguments());
  186. // Empty arguments
  187. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  188. KeyPrefixProcessor::evalKeys($command, 'prefix:');
  189. $this->assertEmpty($command->getArguments());
  190. }
  191. /**
  192. * @group disconnected
  193. */
  194. public function testPrefixMigrate()
  195. {
  196. $arguments = array('127.0.0.1', '6379', 'key', '0', '10', 'COPY', 'REPLACE');
  197. $expected = array('127.0.0.1', '6379', 'prefix:key', '0', '10', 'COPY', 'REPLACE');
  198. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  199. $command->setRawArguments($arguments);
  200. KeyPrefixProcessor::migrate($command, 'prefix:');
  201. $this->assertSame($expected, $command->getArguments());
  202. // Empty arguments
  203. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  204. KeyPrefixProcessor::sort($command, 'prefix:');
  205. $this->assertEmpty($command->getArguments());
  206. }
  207. /**
  208. * @group disconnected
  209. * @dataProvider commandArgumentsDataProvider
  210. *
  211. * @param string $commandID
  212. * @param array $arguments
  213. * @param array $expected
  214. */
  215. public function testApplyPrefixToCommand($commandID, array $arguments, array $expected)
  216. {
  217. $processor = new KeyPrefixProcessor('prefix:');
  218. $command = $this->getCommandInstance($commandID, $arguments);
  219. $processor->process($command);
  220. $this->assertSame($expected, $command->getArguments());
  221. }
  222. /**
  223. * @group disconnected
  224. */
  225. public function testCanDefineNewCommandHandlers()
  226. {
  227. $command = $this->getCommandInstance('NEWCMD', array('key', 'value'));
  228. $callable = $this->getMock('stdClass', array('__invoke'));
  229. $callable->expects($this->once())
  230. ->method('__invoke')
  231. ->with($command, 'prefix:')
  232. ->will($this->returnCallback(function ($command, $prefix) {
  233. $command->setRawArguments(array('prefix:key', 'value'));
  234. }));
  235. $processor = new KeyPrefixProcessor('prefix:');
  236. $processor->setCommandHandler('NEWCMD', $callable);
  237. $processor->process($command);
  238. $this->assertSame(array('prefix:key', 'value'), $command->getArguments());
  239. }
  240. /**
  241. * @group disconnected
  242. */
  243. public function testCanOverrideExistingCommandHandlers()
  244. {
  245. $command = $this->getCommandInstance('SET', array('key', 'value'));
  246. $callable = $this->getMock('stdClass', array('__invoke'));
  247. $callable->expects($this->once())
  248. ->method('__invoke')
  249. ->with($command, 'prefix:')
  250. ->will($this->returnCallback(function ($command, $prefix) {
  251. $command->setRawArguments(array('prefix:key', 'value'));
  252. }));
  253. $processor = new KeyPrefixProcessor('prefix:');
  254. $processor->setCommandHandler('SET', $callable);
  255. $processor->process($command);
  256. $this->assertSame(array('prefix:key', 'value'), $command->getArguments());
  257. }
  258. /**
  259. * @group disconnected
  260. */
  261. public function testCanUndefineCommandHandlers()
  262. {
  263. $command = $this->getCommandInstance('SET', array('key', 'value'));
  264. $processor = new KeyPrefixProcessor('prefix:');
  265. $processor->setCommandHandler('SET', null);
  266. $processor->process($command);
  267. $this->assertSame(array('key', 'value'), $command->getArguments());
  268. }
  269. // ******************************************************************** //
  270. // ---- HELPER METHODS ------------------------------------------------ //
  271. // ******************************************************************** //
  272. public function getCommandInstance($commandID, array $arguments)
  273. {
  274. $command = new RawCommand(array($commandID));
  275. $command->setRawArguments($arguments);
  276. return $command;
  277. }
  278. /**
  279. * Data provider for key prefixing test.
  280. *
  281. * @return array
  282. */
  283. public function commandArgumentsDataProvider()
  284. {
  285. return array(
  286. /* ---------------- Redis 1.2 ---------------- */
  287. array('EXISTS',
  288. array('key'),
  289. array('prefix:key'),
  290. ),
  291. array('DEL',
  292. array('key1', 'key2', 'key3'),
  293. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  294. ),
  295. array('TYPE',
  296. array('key'),
  297. array('prefix:key'),
  298. ),
  299. array('KEYS',
  300. array('pattern'),
  301. array('prefix:pattern'),
  302. ),
  303. array('RENAME',
  304. array('key', 'newkey'),
  305. array('prefix:key', 'prefix:newkey'),
  306. ),
  307. array('RENAMENX',
  308. array('key', 'newkey'),
  309. array('prefix:key', 'prefix:newkey'),
  310. ),
  311. array('EXPIRE',
  312. array('key', 'value'),
  313. array('prefix:key', 'value'),
  314. ),
  315. array('EXPIREAT',
  316. array('key', 'value'),
  317. array('prefix:key', 'value'),
  318. ),
  319. array('TTL',
  320. array('key', 10),
  321. array('prefix:key', 10),
  322. ),
  323. array('MOVE',
  324. array('key', 'db'),
  325. array('prefix:key', 'db'),
  326. ),
  327. array('SORT',
  328. array('key'),
  329. array('prefix:key'),
  330. ),
  331. array('SORT',
  332. array('key', 'BY', 'by_key_*'),
  333. array('prefix:key', 'BY', 'prefix:by_key_*'),
  334. ),
  335. array('SORT',
  336. array('key', 'BY', 'by_key_*', 'STORE', 'destination_key'),
  337. array('prefix:key', 'BY', 'prefix:by_key_*', 'STORE', 'prefix:destination_key'),
  338. ),
  339. array('SORT',
  340. array('key', 'BY', 'by_key_*', 'GET', 'object_*', 'GET', '#', 'LIMIT', 1, 4, 'ASC', 'ALPHA', 'STORE', 'destination_key'),
  341. array('prefix:key', 'BY', 'prefix:by_key_*', 'GET', 'prefix:object_*', 'GET', '#', 'LIMIT', 1, 4, 'ASC', 'ALPHA', 'STORE', 'prefix:destination_key'),
  342. ),
  343. array('DUMP',
  344. array('key'),
  345. array('prefix:key'),
  346. ),
  347. array('RESTORE',
  348. array('key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_("),
  349. array('prefix:key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_("),
  350. ),
  351. array('SET',
  352. array('key', 'value'),
  353. array('prefix:key', 'value'),
  354. ),
  355. array('SET',
  356. array('key', 'value', 'EX', 10, 'NX'),
  357. array('prefix:key', 'value', 'EX', 10, 'NX'),
  358. ),
  359. array('SETNX',
  360. array('key', 'value'),
  361. array('prefix:key', 'value'),
  362. ),
  363. array('MSET',
  364. array('foo', 'bar', 'hoge', 'piyo'),
  365. array('prefix:foo', 'bar', 'prefix:hoge', 'piyo'),
  366. ),
  367. array('MSETNX',
  368. array('foo', 'bar', 'hoge', 'piyo'),
  369. array('prefix:foo', 'bar', 'prefix:hoge', 'piyo'),
  370. ),
  371. array('GET',
  372. array('key'),
  373. array('prefix:key'),
  374. ),
  375. array('MGET',
  376. array('key1', 'key2', 'key3'),
  377. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  378. ),
  379. array('GETSET',
  380. array('key', 'value'),
  381. array('prefix:key', 'value'),
  382. ),
  383. array('INCR',
  384. array('key'),
  385. array('prefix:key'),
  386. ),
  387. array('INCRBY',
  388. array('key', 5),
  389. array('prefix:key', 5),
  390. ),
  391. array('DECR',
  392. array('key'),
  393. array('prefix:key'),
  394. ),
  395. array('DECRBY',
  396. array('key', 5),
  397. array('prefix:key', 5),
  398. ),
  399. array('RPUSH',
  400. array('key', 'value1', 'value2', 'value3'),
  401. array('prefix:key', 'value1', 'value2', 'value3'),
  402. ),
  403. array('LPUSH',
  404. array('key', 'value1', 'value2', 'value3'),
  405. array('prefix:key', 'value1', 'value2', 'value3'),
  406. ),
  407. array('LLEN',
  408. array('key'),
  409. array('prefix:key'),
  410. ),
  411. array('LRANGE',
  412. array('key', 0, -1),
  413. array('prefix:key', 0, -1),
  414. ),
  415. array('LTRIM',
  416. array('key', 0, 1),
  417. array('prefix:key', 0, 1),
  418. ),
  419. array('LINDEX',
  420. array('key', 1),
  421. array('prefix:key', 1),
  422. ),
  423. array('LSET',
  424. array('key', 0, 'value'),
  425. array('prefix:key', 0, 'value'),
  426. ),
  427. array('LREM',
  428. array('key', 0, 'value'),
  429. array('prefix:key', 0, 'value'),
  430. ),
  431. array('LPOP',
  432. array('key'),
  433. array('prefix:key'),
  434. ),
  435. array('RPOP',
  436. array('key'),
  437. array('prefix:key'),
  438. ),
  439. array('RPOPLPUSH',
  440. array('key:source', 'key:destination'),
  441. array('prefix:key:source', 'prefix:key:destination'),
  442. ),
  443. array('SADD',
  444. array('key', 'member1', 'member2', 'member3'),
  445. array('prefix:key', 'member1', 'member2', 'member3'),
  446. ),
  447. array('SREM',
  448. array('key', 'member1', 'member2', 'member3'),
  449. array('prefix:key', 'member1', 'member2', 'member3'),
  450. ),
  451. array('SPOP',
  452. array('key'),
  453. array('prefix:key'),
  454. ),
  455. array('SMOVE',
  456. array('key:source', 'key:destination', 'member'),
  457. array('prefix:key:source', 'prefix:key:destination', 'member'),
  458. ),
  459. array('SCARD',
  460. array('key'),
  461. array('prefix:key'),
  462. ),
  463. array('SISMEMBER',
  464. array('key', 'member'),
  465. array('prefix:key', 'member'),
  466. ),
  467. array('SINTER',
  468. array('key1', 'key2', 'key3'),
  469. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  470. ),
  471. array('SINTERSTORE',
  472. array('key:destination', 'key1', 'key2'),
  473. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  474. ),
  475. array('SUNION',
  476. array('key1', 'key2', 'key3'),
  477. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  478. ),
  479. array('SUNIONSTORE',
  480. array('key:destination', 'key1', 'key2'),
  481. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  482. ),
  483. array('SDIFF',
  484. array('key1', 'key2', 'key3'),
  485. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  486. ),
  487. array('SDIFFSTORE',
  488. array('key:destination', 'key1', 'key2'),
  489. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  490. ),
  491. array('SMEMBERS',
  492. array('key'),
  493. array('prefix:key'),
  494. ),
  495. array('SRANDMEMBER',
  496. array('key', 1),
  497. array('prefix:key', 1),
  498. ),
  499. array('ZADD',
  500. array('key', 'score1', 'member1', 'score2', 'member2'),
  501. array('prefix:key', 'score1', 'member1', 'score2', 'member2'),
  502. ),
  503. array('ZINCRBY',
  504. array('key', 1.0, 'member'),
  505. array('prefix:key', 1.0, 'member'),
  506. ),
  507. array('ZREM',
  508. array('key', 'member1', 'member2', 'member3'),
  509. array('prefix:key', 'member1', 'member2', 'member3'),
  510. ),
  511. array('ZRANGE',
  512. array('key', 0, 100, 'WITHSCORES'),
  513. array('prefix:key', 0, 100, 'WITHSCORES'),
  514. ),
  515. array('ZREVRANGE',
  516. array('key', 0, 100, 'WITHSCORES'),
  517. array('prefix:key', 0, 100, 'WITHSCORES'),
  518. ),
  519. array('ZRANGEBYSCORE',
  520. array('key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  521. array('prefix:key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  522. ),
  523. array('ZCARD',
  524. array('key'),
  525. array('prefix:key'),
  526. ),
  527. array('ZSCORE',
  528. array('key', 'member'),
  529. array('prefix:key', 'member'),
  530. ),
  531. array('ZREMRANGEBYSCORE',
  532. array('key', 0, 10),
  533. array('prefix:key', 0, 10),
  534. ),
  535. /* ---------------- Redis 2.0 ---------------- */
  536. array('SETEX',
  537. array('key', 10, 'value'),
  538. array('prefix:key', 10, 'value'),
  539. ),
  540. array('APPEND',
  541. array('key', 'value'),
  542. array('prefix:key', 'value'),
  543. ),
  544. array('SUBSTR',
  545. array('key', 5, 10),
  546. array('prefix:key', 5, 10),
  547. ),
  548. array('BLPOP',
  549. array('key1', 'key2', 'key3', 10),
  550. array('prefix:key1', 'prefix:key2', 'prefix:key3', 10),
  551. ),
  552. array('BRPOP',
  553. array('key1', 'key2', 'key3', 10),
  554. array('prefix:key1', 'prefix:key2', 'prefix:key3', 10),
  555. ),
  556. array('ZUNIONSTORE',
  557. array('key:destination', 2, 'key1', 'key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  558. array('prefix:key:destination', 2, 'prefix:key1', 'prefix:key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  559. ),
  560. array('ZINTERSTORE',
  561. array('key:destination', 2, 'key1', 'key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  562. array('prefix:key:destination', 2, 'prefix:key1', 'prefix:key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  563. ),
  564. array('ZCOUNT',
  565. array('key', 0, 10),
  566. array('prefix:key', 0, 10),
  567. ),
  568. array('ZRANK',
  569. array('key', 'member'),
  570. array('prefix:key', 'member'),
  571. ),
  572. array('ZREVRANK',
  573. array('key', 'member'),
  574. array('prefix:key', 'member'),
  575. ),
  576. array('ZREMRANGEBYRANK',
  577. array('key', 0, 10),
  578. array('prefix:key', 0, 10),
  579. ),
  580. array('HSET',
  581. array('key', 'field', 'value'),
  582. array('prefix:key', 'field', 'value'),
  583. ),
  584. array('HSETNX',
  585. array('key', 'field', 'value'),
  586. array('prefix:key', 'field', 'value'),
  587. ),
  588. array('HMSET',
  589. array('key', 'field1', 'value1', 'field2', 'value2'),
  590. array('prefix:key', 'field1', 'value1', 'field2', 'value2'),
  591. ),
  592. array('HINCRBY',
  593. array('key', 'field', 10),
  594. array('prefix:key', 'field', 10),
  595. ),
  596. array('HGET',
  597. array('key', 'field'),
  598. array('prefix:key', 'field'),
  599. ),
  600. array('HMGET',
  601. array('key', 'field1', 'field2', 'field3'),
  602. array('prefix:key', 'field1', 'field2', 'field3'),
  603. ),
  604. array('HDEL',
  605. array('key', 'field1', 'field2', 'field3'),
  606. array('prefix:key', 'field1', 'field2', 'field3'),
  607. ),
  608. array('HEXISTS',
  609. array('key', 'field'),
  610. array('prefix:key', 'field'),
  611. ),
  612. array('HLEN',
  613. array('key'),
  614. array('prefix:key'),
  615. ),
  616. array('HKEYS',
  617. array('key'),
  618. array('prefix:key'),
  619. ),
  620. array('HVALS',
  621. array('key'),
  622. array('prefix:key'),
  623. ),
  624. array('HGETALL',
  625. array('key'),
  626. array('prefix:key'),
  627. ),
  628. array('SUBSCRIBE',
  629. array('channel:foo', 'channel:hoge'),
  630. array('prefix:channel:foo', 'prefix:channel:hoge'),
  631. ),
  632. array('UNSUBSCRIBE',
  633. array('channel:foo', 'channel:hoge'),
  634. array('prefix:channel:foo', 'prefix:channel:hoge'),
  635. ),
  636. array('PSUBSCRIBE',
  637. array('channel:foo:*', 'channel:hoge:*'),
  638. array('prefix:channel:foo:*', 'prefix:channel:hoge:*'),
  639. ),
  640. array('PUNSUBSCRIBE',
  641. array('channel:foo:*', 'channel:hoge:*'),
  642. array('prefix:channel:foo:*', 'prefix:channel:hoge:*'),
  643. ),
  644. array('PUBLISH',
  645. array('channel', 'message'),
  646. array('prefix:channel', 'message'),
  647. ),
  648. /* ---------------- Redis 2.2 ---------------- */
  649. array('PERSIST',
  650. array('key'),
  651. array('prefix:key'),
  652. ),
  653. array('STRLEN',
  654. array('key'),
  655. array('prefix:key'),
  656. ),
  657. array('SETRANGE',
  658. array('key', 5, 'string'),
  659. array('prefix:key', 5, 'string'),
  660. ),
  661. array('GETRANGE',
  662. array('key', 5, 10),
  663. array('prefix:key', 5, 10),
  664. ),
  665. array('SETBIT',
  666. array('key', 7, 1),
  667. array('prefix:key', 7, 1),
  668. ),
  669. array('GETBIT',
  670. array('key', 100),
  671. array('prefix:key', 100),
  672. ),
  673. array('RPUSHX',
  674. array('key', 'value'),
  675. array('prefix:key', 'value'),
  676. ),
  677. array('LPUSHX',
  678. array('key', 'value'),
  679. array('prefix:key', 'value'),
  680. ),
  681. array('LINSERT',
  682. array('key', 'before', 'value1', 'value2'),
  683. array('prefix:key', 'before', 'value1', 'value2'),
  684. ),
  685. array('BRPOPLPUSH',
  686. array('key:source', 'key:destination', 10),
  687. array('prefix:key:source', 'prefix:key:destination', 10),
  688. ),
  689. array('ZREVRANGEBYSCORE',
  690. array('key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  691. array('prefix:key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  692. ),
  693. array('WATCH',
  694. array('key1', 'key2', 'key3'),
  695. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  696. ),
  697. /* ---------------- Redis 2.6 ---------------- */
  698. array('PTTL',
  699. array('key', 10),
  700. array('prefix:key', 10),
  701. ),
  702. array('PEXPIRE',
  703. array('key', 1500),
  704. array('prefix:key', 1500),
  705. ),
  706. array('PEXPIREAT',
  707. array('key', 1555555555005),
  708. array('prefix:key', 1555555555005),
  709. ),
  710. array('PSETEX',
  711. array('key', 1500, 'value'),
  712. array('prefix:key', 1500, 'value'),
  713. ),
  714. array('INCRBYFLOAT',
  715. array('key', 10.5),
  716. array('prefix:key', 10.5),
  717. ),
  718. array('BITOP',
  719. array('AND', 'key:dst', 'key:01', 'key:02'),
  720. array('AND', 'prefix:key:dst', 'prefix:key:01', 'prefix:key:02'),
  721. ),
  722. array('BITCOUNT',
  723. array('key', 0, 10),
  724. array('prefix:key', 0, 10),
  725. ),
  726. array('HINCRBYFLOAT',
  727. array('key', 'field', 10.5),
  728. array('prefix:key', 'field', 10.5),
  729. ),
  730. array('EVAL',
  731. array('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'foo', 'hoge', 'bar', 'piyo'),
  732. array('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'prefix:foo', 'prefix:hoge', 'bar', 'piyo'),
  733. ),
  734. array('EVALSHA',
  735. array('a42059b356c875f0717db19a51f6aaca9ae659ea', 2, 'foo', 'hoge', 'bar', 'piyo'),
  736. array('a42059b356c875f0717db19a51f6aaca9ae659ea', 2, 'prefix:foo', 'prefix:hoge', 'bar', 'piyo'),
  737. ),
  738. array('BITPOS',
  739. array('key', 0),
  740. array('prefix:key', 0),
  741. ),
  742. array('MIGRATE',
  743. array('127.0.0.1', '6379', 'key', '0', '10'),
  744. array('127.0.0.1', '6379', 'prefix:key', '0', '10'),
  745. ),
  746. /* ---------------- Redis 2.8 ---------------- */
  747. array('SSCAN',
  748. array('key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  749. array('prefix:key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  750. ),
  751. array('ZSCAN',
  752. array('key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  753. array('prefix:key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  754. ),
  755. array('HSCAN',
  756. array('key', '0', 'MATCH', 'field:*', 'COUNT', 10),
  757. array('prefix:key', '0', 'MATCH', 'field:*', 'COUNT', 10),
  758. ),
  759. array('PFADD',
  760. array('key', 'a', 'b', 'c'),
  761. array('prefix:key', 'a', 'b', 'c'),
  762. ),
  763. array('PFCOUNT',
  764. array('key:1', 'key:2', 'key:3'),
  765. array('prefix:key:1', 'prefix:key:2', 'prefix:key:3'),
  766. ),
  767. array('PFMERGE',
  768. array('key:1', 'key:2', 'key:3'),
  769. array('prefix:key:1', 'prefix:key:2', 'prefix:key:3'),
  770. ),
  771. array('ZLEXCOUNT',
  772. array('key', '-', '+'),
  773. array('prefix:key', '-', '+'),
  774. ),
  775. array('ZRANGEBYLEX',
  776. array('key', '-', '+', 'LIMIT', '0', '10'),
  777. array('prefix:key', '-', '+', 'LIMIT', '0', '10'),
  778. ),
  779. array('ZREMRANGEBYLEX',
  780. array('key', '-', '+'),
  781. array('prefix:key', '-', '+'),
  782. ),
  783. array('ZREVRANGEBYLEX',
  784. array('key', '+', '-', 'LIMIT', '0', '10'),
  785. array('prefix:key', '+', '-', 'LIMIT', '0', '10'),
  786. ),
  787. /* ---------------- Redis 3.0 ---------------- */
  788. array('MIGRATE',
  789. array('127.0.0.1', '6379', 'key', '0', '10', 'COPY', 'REPLACE'),
  790. array('127.0.0.1', '6379', 'prefix:key', '0', '10', 'COPY', 'REPLACE'),
  791. ),
  792. array('EXISTS',
  793. array('key1', 'key2', 'key3'),
  794. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  795. ),
  796. /* ---------------- Redis 3.2 ---------------- */
  797. array('HSTRLEN',
  798. array('key', 'field'),
  799. array('prefix:key', 'field'),
  800. ),
  801. array('BITFIELD',
  802. array('key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
  803. array('prefix:key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
  804. ),
  805. array('GEOADD',
  806. array('key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
  807. array('prefix:key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
  808. ),
  809. array('GEOHASH',
  810. array('key', 'member:1', 'member:2'),
  811. array('prefix:key', 'member:1', 'member:2'),
  812. ),
  813. array('GEOPOS',
  814. array('key', 'member:1', 'member:2'),
  815. array('prefix:key', 'member:1', 'member:2'),
  816. ),
  817. array('GEODIST',
  818. array('key', 'member:1', 'member:2', 'km'),
  819. array('prefix:key', 'member:1', 'member:2', 'km'),
  820. ),
  821. array('GEORADIUS',
  822. array('key', '15', '37', '200', 'km'),
  823. array('prefix:key', '15', '37', '200', 'km'),
  824. ),
  825. array('GEORADIUS',
  826. array('key', '15', '37', '200', 'km', 'WITHDIST', 'STORE', 'key:store', 'STOREDIST', 'key:storedist'),
  827. array('prefix:key', '15', '37', '200', 'km', 'WITHDIST', 'STORE', 'prefix:key:store', 'STOREDIST', 'prefix:key:storedist'),
  828. ),
  829. array('GEORADIUSBYMEMBER',
  830. array('key', 'member', '100', 'km'),
  831. array('prefix:key', 'member', '100', 'km'),
  832. ),
  833. array('GEORADIUSBYMEMBER',
  834. array('key', 'member', '100', 'km', 'WITHDIST', 'STORE', 'key:store', 'STOREDIST', 'key:storedist'),
  835. array('prefix:key', 'member', '100', 'km', 'WITHDIST', 'STORE', 'prefix:key:store', 'STOREDIST', 'prefix:key:storedist'),
  836. ),
  837. );
  838. }
  839. }