KeyPrefixProcessorTest.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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. * @group disconnected
  271. * @expectedException \InvalidArgumentException
  272. * @expectedExceptionMessage Callback must be a valid callable object or NULL
  273. */
  274. public function testCannotDefineCommandHandlerWithInvalidType()
  275. {
  276. $processor = new KeyPrefixProcessor('prefix:');
  277. $processor->setCommandHandler('NEWCMD', new \stdClass());
  278. }
  279. // ******************************************************************** //
  280. // ---- HELPER METHODS ------------------------------------------------ //
  281. // ******************************************************************** //
  282. public function getCommandInstance($commandID, array $arguments)
  283. {
  284. $command = new RawCommand($commandID);
  285. $command->setRawArguments($arguments);
  286. return $command;
  287. }
  288. /**
  289. * Data provider for key prefixing test.
  290. *
  291. * @return array
  292. */
  293. public function commandArgumentsDataProvider()
  294. {
  295. return array(
  296. /* ---------------- Redis 1.2 ---------------- */
  297. array('EXISTS',
  298. array('key'),
  299. array('prefix:key'),
  300. ),
  301. array('DEL',
  302. array('key1', 'key2', 'key3'),
  303. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  304. ),
  305. array('TYPE',
  306. array('key'),
  307. array('prefix:key'),
  308. ),
  309. array('KEYS',
  310. array('pattern'),
  311. array('prefix:pattern'),
  312. ),
  313. array('RENAME',
  314. array('key', 'newkey'),
  315. array('prefix:key', 'prefix:newkey'),
  316. ),
  317. array('RENAMENX',
  318. array('key', 'newkey'),
  319. array('prefix:key', 'prefix:newkey'),
  320. ),
  321. array('EXPIRE',
  322. array('key', 'value'),
  323. array('prefix:key', 'value'),
  324. ),
  325. array('EXPIREAT',
  326. array('key', 'value'),
  327. array('prefix:key', 'value'),
  328. ),
  329. array('TTL',
  330. array('key', 10),
  331. array('prefix:key', 10),
  332. ),
  333. array('MOVE',
  334. array('key', 'db'),
  335. array('prefix:key', 'db'),
  336. ),
  337. array('SORT',
  338. array('key'),
  339. array('prefix:key'),
  340. ),
  341. array('SORT',
  342. array('key', 'BY', 'by_key_*'),
  343. array('prefix:key', 'BY', 'prefix:by_key_*'),
  344. ),
  345. array('SORT',
  346. array('key', 'BY', 'by_key_*', 'STORE', 'destination_key'),
  347. array('prefix:key', 'BY', 'prefix:by_key_*', 'STORE', 'prefix:destination_key'),
  348. ),
  349. array('SORT',
  350. array('key', 'BY', 'by_key_*', 'GET', 'object_*', 'GET', '#', 'LIMIT', 1, 4, 'ASC', 'ALPHA', 'STORE', 'destination_key'),
  351. array('prefix:key', 'BY', 'prefix:by_key_*', 'GET', 'prefix:object_*', 'GET', '#', 'LIMIT', 1, 4, 'ASC', 'ALPHA', 'STORE', 'prefix:destination_key'),
  352. ),
  353. array('DUMP',
  354. array('key'),
  355. array('prefix:key'),
  356. ),
  357. array('RESTORE',
  358. array('key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_("),
  359. array('prefix:key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_("),
  360. ),
  361. array('SET',
  362. array('key', 'value'),
  363. array('prefix:key', 'value'),
  364. ),
  365. array('SET',
  366. array('key', 'value', 'EX', 10, 'NX'),
  367. array('prefix:key', 'value', 'EX', 10, 'NX'),
  368. ),
  369. array('SETNX',
  370. array('key', 'value'),
  371. array('prefix:key', 'value'),
  372. ),
  373. array('MSET',
  374. array('foo', 'bar', 'hoge', 'piyo'),
  375. array('prefix:foo', 'bar', 'prefix:hoge', 'piyo'),
  376. ),
  377. array('MSETNX',
  378. array('foo', 'bar', 'hoge', 'piyo'),
  379. array('prefix:foo', 'bar', 'prefix:hoge', 'piyo'),
  380. ),
  381. array('GET',
  382. array('key'),
  383. array('prefix:key'),
  384. ),
  385. array('MGET',
  386. array('key1', 'key2', 'key3'),
  387. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  388. ),
  389. array('GETSET',
  390. array('key', 'value'),
  391. array('prefix:key', 'value'),
  392. ),
  393. array('INCR',
  394. array('key'),
  395. array('prefix:key'),
  396. ),
  397. array('INCRBY',
  398. array('key', 5),
  399. array('prefix:key', 5),
  400. ),
  401. array('DECR',
  402. array('key'),
  403. array('prefix:key'),
  404. ),
  405. array('DECRBY',
  406. array('key', 5),
  407. array('prefix:key', 5),
  408. ),
  409. array('RPUSH',
  410. array('key', 'value1', 'value2', 'value3'),
  411. array('prefix:key', 'value1', 'value2', 'value3'),
  412. ),
  413. array('LPUSH',
  414. array('key', 'value1', 'value2', 'value3'),
  415. array('prefix:key', 'value1', 'value2', 'value3'),
  416. ),
  417. array('LLEN',
  418. array('key'),
  419. array('prefix:key'),
  420. ),
  421. array('LRANGE',
  422. array('key', 0, -1),
  423. array('prefix:key', 0, -1),
  424. ),
  425. array('LTRIM',
  426. array('key', 0, 1),
  427. array('prefix:key', 0, 1),
  428. ),
  429. array('LINDEX',
  430. array('key', 1),
  431. array('prefix:key', 1),
  432. ),
  433. array('LSET',
  434. array('key', 0, 'value'),
  435. array('prefix:key', 0, 'value'),
  436. ),
  437. array('LREM',
  438. array('key', 0, 'value'),
  439. array('prefix:key', 0, 'value'),
  440. ),
  441. array('LPOP',
  442. array('key'),
  443. array('prefix:key'),
  444. ),
  445. array('RPOP',
  446. array('key'),
  447. array('prefix:key'),
  448. ),
  449. array('RPOPLPUSH',
  450. array('key:source', 'key:destination'),
  451. array('prefix:key:source', 'prefix:key:destination'),
  452. ),
  453. array('SADD',
  454. array('key', 'member1', 'member2', 'member3'),
  455. array('prefix:key', 'member1', 'member2', 'member3'),
  456. ),
  457. array('SREM',
  458. array('key', 'member1', 'member2', 'member3'),
  459. array('prefix:key', 'member1', 'member2', 'member3'),
  460. ),
  461. array('SPOP',
  462. array('key'),
  463. array('prefix:key'),
  464. ),
  465. array('SMOVE',
  466. array('key:source', 'key:destination', 'member'),
  467. array('prefix:key:source', 'prefix:key:destination', 'member'),
  468. ),
  469. array('SCARD',
  470. array('key'),
  471. array('prefix:key'),
  472. ),
  473. array('SISMEMBER',
  474. array('key', 'member'),
  475. array('prefix:key', 'member'),
  476. ),
  477. array('SINTER',
  478. array('key1', 'key2', 'key3'),
  479. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  480. ),
  481. array('SINTERSTORE',
  482. array('key:destination', 'key1', 'key2'),
  483. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  484. ),
  485. array('SUNION',
  486. array('key1', 'key2', 'key3'),
  487. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  488. ),
  489. array('SUNIONSTORE',
  490. array('key:destination', 'key1', 'key2'),
  491. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  492. ),
  493. array('SDIFF',
  494. array('key1', 'key2', 'key3'),
  495. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  496. ),
  497. array('SDIFFSTORE',
  498. array('key:destination', 'key1', 'key2'),
  499. array('prefix:key:destination', 'prefix:key1', 'prefix:key2'),
  500. ),
  501. array('SMEMBERS',
  502. array('key'),
  503. array('prefix:key'),
  504. ),
  505. array('SRANDMEMBER',
  506. array('key', 1),
  507. array('prefix:key', 1),
  508. ),
  509. array('ZADD',
  510. array('key', 'score1', 'member1', 'score2', 'member2'),
  511. array('prefix:key', 'score1', 'member1', 'score2', 'member2'),
  512. ),
  513. array('ZINCRBY',
  514. array('key', 1.0, 'member'),
  515. array('prefix:key', 1.0, 'member'),
  516. ),
  517. array('ZREM',
  518. array('key', 'member1', 'member2', 'member3'),
  519. array('prefix:key', 'member1', 'member2', 'member3'),
  520. ),
  521. array('ZRANGE',
  522. array('key', 0, 100, 'WITHSCORES'),
  523. array('prefix:key', 0, 100, 'WITHSCORES'),
  524. ),
  525. array('ZREVRANGE',
  526. array('key', 0, 100, 'WITHSCORES'),
  527. array('prefix:key', 0, 100, 'WITHSCORES'),
  528. ),
  529. array('ZRANGEBYSCORE',
  530. array('key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  531. array('prefix:key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  532. ),
  533. array('ZCARD',
  534. array('key'),
  535. array('prefix:key'),
  536. ),
  537. array('ZSCORE',
  538. array('key', 'member'),
  539. array('prefix:key', 'member'),
  540. ),
  541. array('ZREMRANGEBYSCORE',
  542. array('key', 0, 10),
  543. array('prefix:key', 0, 10),
  544. ),
  545. /* ---------------- Redis 2.0 ---------------- */
  546. array('SETEX',
  547. array('key', 10, 'value'),
  548. array('prefix:key', 10, 'value'),
  549. ),
  550. array('APPEND',
  551. array('key', 'value'),
  552. array('prefix:key', 'value'),
  553. ),
  554. array('SUBSTR',
  555. array('key', 5, 10),
  556. array('prefix:key', 5, 10),
  557. ),
  558. array('BLPOP',
  559. array('key1', 'key2', 'key3', 10),
  560. array('prefix:key1', 'prefix:key2', 'prefix:key3', 10),
  561. ),
  562. array('BRPOP',
  563. array('key1', 'key2', 'key3', 10),
  564. array('prefix:key1', 'prefix:key2', 'prefix:key3', 10),
  565. ),
  566. array('ZUNIONSTORE',
  567. array('key:destination', 2, 'key1', 'key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  568. array('prefix:key:destination', 2, 'prefix:key1', 'prefix:key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  569. ),
  570. array('ZINTERSTORE',
  571. array('key:destination', 2, 'key1', 'key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  572. array('prefix:key:destination', 2, 'prefix:key1', 'prefix:key2', 'WEIGHTS', 10, 100, 'AGGREGATE', 'sum'),
  573. ),
  574. array('ZCOUNT',
  575. array('key', 0, 10),
  576. array('prefix:key', 0, 10),
  577. ),
  578. array('ZRANK',
  579. array('key', 'member'),
  580. array('prefix:key', 'member'),
  581. ),
  582. array('ZREVRANK',
  583. array('key', 'member'),
  584. array('prefix:key', 'member'),
  585. ),
  586. array('ZREMRANGEBYRANK',
  587. array('key', 0, 10),
  588. array('prefix:key', 0, 10),
  589. ),
  590. array('HSET',
  591. array('key', 'field', 'value'),
  592. array('prefix:key', 'field', 'value'),
  593. ),
  594. array('HSETNX',
  595. array('key', 'field', 'value'),
  596. array('prefix:key', 'field', 'value'),
  597. ),
  598. array('HMSET',
  599. array('key', 'field1', 'value1', 'field2', 'value2'),
  600. array('prefix:key', 'field1', 'value1', 'field2', 'value2'),
  601. ),
  602. array('HINCRBY',
  603. array('key', 'field', 10),
  604. array('prefix:key', 'field', 10),
  605. ),
  606. array('HGET',
  607. array('key', 'field'),
  608. array('prefix:key', 'field'),
  609. ),
  610. array('HMGET',
  611. array('key', 'field1', 'field2', 'field3'),
  612. array('prefix:key', 'field1', 'field2', 'field3'),
  613. ),
  614. array('HDEL',
  615. array('key', 'field1', 'field2', 'field3'),
  616. array('prefix:key', 'field1', 'field2', 'field3'),
  617. ),
  618. array('HEXISTS',
  619. array('key', 'field'),
  620. array('prefix:key', 'field'),
  621. ),
  622. array('HLEN',
  623. array('key'),
  624. array('prefix:key'),
  625. ),
  626. array('HKEYS',
  627. array('key'),
  628. array('prefix:key'),
  629. ),
  630. array('HVALS',
  631. array('key'),
  632. array('prefix:key'),
  633. ),
  634. array('HGETALL',
  635. array('key'),
  636. array('prefix:key'),
  637. ),
  638. array('SUBSCRIBE',
  639. array('channel:foo', 'channel:hoge'),
  640. array('prefix:channel:foo', 'prefix:channel:hoge'),
  641. ),
  642. array('UNSUBSCRIBE',
  643. array('channel:foo', 'channel:hoge'),
  644. array('prefix:channel:foo', 'prefix:channel:hoge'),
  645. ),
  646. array('PSUBSCRIBE',
  647. array('channel:foo:*', 'channel:hoge:*'),
  648. array('prefix:channel:foo:*', 'prefix:channel:hoge:*'),
  649. ),
  650. array('PUNSUBSCRIBE',
  651. array('channel:foo:*', 'channel:hoge:*'),
  652. array('prefix:channel:foo:*', 'prefix:channel:hoge:*'),
  653. ),
  654. array('PUBLISH',
  655. array('channel', 'message'),
  656. array('prefix:channel', 'message'),
  657. ),
  658. /* ---------------- Redis 2.2 ---------------- */
  659. array('PERSIST',
  660. array('key'),
  661. array('prefix:key'),
  662. ),
  663. array('STRLEN',
  664. array('key'),
  665. array('prefix:key'),
  666. ),
  667. array('SETRANGE',
  668. array('key', 5, 'string'),
  669. array('prefix:key', 5, 'string'),
  670. ),
  671. array('GETRANGE',
  672. array('key', 5, 10),
  673. array('prefix:key', 5, 10),
  674. ),
  675. array('SETBIT',
  676. array('key', 7, 1),
  677. array('prefix:key', 7, 1),
  678. ),
  679. array('GETBIT',
  680. array('key', 100),
  681. array('prefix:key', 100),
  682. ),
  683. array('RPUSHX',
  684. array('key', 'value'),
  685. array('prefix:key', 'value'),
  686. ),
  687. array('LPUSHX',
  688. array('key', 'value'),
  689. array('prefix:key', 'value'),
  690. ),
  691. array('LINSERT',
  692. array('key', 'before', 'value1', 'value2'),
  693. array('prefix:key', 'before', 'value1', 'value2'),
  694. ),
  695. array('BRPOPLPUSH',
  696. array('key:source', 'key:destination', 10),
  697. array('prefix:key:source', 'prefix:key:destination', 10),
  698. ),
  699. array('ZREVRANGEBYSCORE',
  700. array('key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  701. array('prefix:key', 0, 100, 'LIMIT', 0, 100, 'WITHSCORES'),
  702. ),
  703. array('WATCH',
  704. array('key1', 'key2', 'key3'),
  705. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  706. ),
  707. /* ---------------- Redis 2.6 ---------------- */
  708. array('PTTL',
  709. array('key', 10),
  710. array('prefix:key', 10),
  711. ),
  712. array('PEXPIRE',
  713. array('key', 1500),
  714. array('prefix:key', 1500),
  715. ),
  716. array('PEXPIREAT',
  717. array('key', 1555555555005),
  718. array('prefix:key', 1555555555005),
  719. ),
  720. array('PSETEX',
  721. array('key', 1500, 'value'),
  722. array('prefix:key', 1500, 'value'),
  723. ),
  724. array('INCRBYFLOAT',
  725. array('key', 10.5),
  726. array('prefix:key', 10.5),
  727. ),
  728. array('BITOP',
  729. array('AND', 'key:dst', 'key:01', 'key:02'),
  730. array('AND', 'prefix:key:dst', 'prefix:key:01', 'prefix:key:02'),
  731. ),
  732. array('BITCOUNT',
  733. array('key', 0, 10),
  734. array('prefix:key', 0, 10),
  735. ),
  736. array('HINCRBYFLOAT',
  737. array('key', 'field', 10.5),
  738. array('prefix:key', 'field', 10.5),
  739. ),
  740. array('EVAL',
  741. array('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'foo', 'hoge', 'bar', 'piyo'),
  742. array('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'prefix:foo', 'prefix:hoge', 'bar', 'piyo'),
  743. ),
  744. array('EVALSHA',
  745. array('a42059b356c875f0717db19a51f6aaca9ae659ea', 2, 'foo', 'hoge', 'bar', 'piyo'),
  746. array('a42059b356c875f0717db19a51f6aaca9ae659ea', 2, 'prefix:foo', 'prefix:hoge', 'bar', 'piyo'),
  747. ),
  748. array('BITPOS',
  749. array('key', 0),
  750. array('prefix:key', 0),
  751. ),
  752. array('MIGRATE',
  753. array('127.0.0.1', '6379', 'key', '0', '10'),
  754. array('127.0.0.1', '6379', 'prefix:key', '0', '10'),
  755. ),
  756. /* ---------------- Redis 2.8 ---------------- */
  757. array('SSCAN',
  758. array('key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  759. array('prefix:key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  760. ),
  761. array('ZSCAN',
  762. array('key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  763. array('prefix:key', '0', 'MATCH', 'member:*', 'COUNT', 10),
  764. ),
  765. array('HSCAN',
  766. array('key', '0', 'MATCH', 'field:*', 'COUNT', 10),
  767. array('prefix:key', '0', 'MATCH', 'field:*', 'COUNT', 10),
  768. ),
  769. array('PFADD',
  770. array('key', 'a', 'b', 'c'),
  771. array('prefix:key', 'a', 'b', 'c'),
  772. ),
  773. array('PFCOUNT',
  774. array('key:1', 'key:2', 'key:3'),
  775. array('prefix:key:1', 'prefix:key:2', 'prefix:key:3'),
  776. ),
  777. array('PFMERGE',
  778. array('key:1', 'key:2', 'key:3'),
  779. array('prefix:key:1', 'prefix:key:2', 'prefix:key:3'),
  780. ),
  781. array('ZLEXCOUNT',
  782. array('key', '-', '+'),
  783. array('prefix:key', '-', '+'),
  784. ),
  785. array('ZRANGEBYLEX',
  786. array('key', '-', '+', 'LIMIT', '0', '10'),
  787. array('prefix:key', '-', '+', 'LIMIT', '0', '10'),
  788. ),
  789. array('ZREMRANGEBYLEX',
  790. array('key', '-', '+'),
  791. array('prefix:key', '-', '+'),
  792. ),
  793. array('ZREVRANGEBYLEX',
  794. array('key', '+', '-', 'LIMIT', '0', '10'),
  795. array('prefix:key', '+', '-', 'LIMIT', '0', '10'),
  796. ),
  797. /* ---------------- Redis 3.0 ---------------- */
  798. array('MIGRATE',
  799. array('127.0.0.1', '6379', 'key', '0', '10', 'COPY', 'REPLACE'),
  800. array('127.0.0.1', '6379', 'prefix:key', '0', '10', 'COPY', 'REPLACE'),
  801. ),
  802. array('EXISTS',
  803. array('key1', 'key2', 'key3'),
  804. array('prefix:key1', 'prefix:key2', 'prefix:key3'),
  805. ),
  806. /* ---------------- Redis 3.2 ---------------- */
  807. array('HSTRLEN',
  808. array('key', 'field'),
  809. array('prefix:key', 'field'),
  810. ),
  811. array('BITFIELD',
  812. array('key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
  813. array('prefix:key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
  814. ),
  815. array('GEOADD',
  816. array('key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
  817. array('prefix:key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
  818. ),
  819. array('GEOHASH',
  820. array('key', 'member:1', 'member:2'),
  821. array('prefix:key', 'member:1', 'member:2'),
  822. ),
  823. array('GEOPOS',
  824. array('key', 'member:1', 'member:2'),
  825. array('prefix:key', 'member:1', 'member:2'),
  826. ),
  827. array('GEODIST',
  828. array('key', 'member:1', 'member:2', 'km'),
  829. array('prefix:key', 'member:1', 'member:2', 'km'),
  830. ),
  831. array('GEORADIUS',
  832. array('key', '15', '37', '200', 'km'),
  833. array('prefix:key', '15', '37', '200', 'km'),
  834. ),
  835. array('GEORADIUS',
  836. array('key', '15', '37', '200', 'km', 'WITHDIST', 'STORE', 'key:store', 'STOREDIST', 'key:storedist'),
  837. array('prefix:key', '15', '37', '200', 'km', 'WITHDIST', 'STORE', 'prefix:key:store', 'STOREDIST', 'prefix:key:storedist'),
  838. ),
  839. array('GEORADIUSBYMEMBER',
  840. array('key', 'member', '100', 'km'),
  841. array('prefix:key', 'member', '100', 'km'),
  842. ),
  843. array('GEORADIUSBYMEMBER',
  844. array('key', 'member', '100', 'km', 'WITHDIST', 'STORE', 'key:store', 'STOREDIST', 'key:storedist'),
  845. array('prefix:key', 'member', '100', 'km', 'WITHDIST', 'STORE', 'prefix:key:store', 'STOREDIST', 'prefix:key:storedist'),
  846. ),
  847. );
  848. }
  849. }