KeyPrefixProcessorTest.php 27 KB

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