KeyPrefixProcessorTest.php 28 KB

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