Predis_Compatibility.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?php
  2. namespace Predis;
  3. class Compatibility {
  4. protected function __construct() {
  5. }
  6. public static function loadRedis_v1_0() {
  7. RedisServerProfile::registerProfile('\Predis\RedisServer_v1_0', '1.0');
  8. }
  9. public static function longMethodNames() {
  10. RedisServerProfile::registerProfile('\Predis\RedisServer_LongNames_v1_2', '1.2');
  11. RedisServerProfile::registerProfile('\Predis\RedisServer_LongNames_v2_0', '2.0');
  12. }
  13. }
  14. /* ------------------------------------------------------------------------- */
  15. class RedisServer_LongNames_v1_2 extends RedisServerProfile {
  16. public function getVersion() { return '1.2'; }
  17. public function getSupportedCommands() {
  18. return array(
  19. /* miscellaneous commands */
  20. 'ping' => '\Predis\Commands\Ping',
  21. 'echo' => '\Predis\Commands\DoEcho',
  22. 'auth' => '\Predis\Commands\Auth',
  23. /* connection handling */
  24. 'quit' => '\Predis\Commands\Quit',
  25. /* commands operating on string values */
  26. 'set' => '\Predis\Commands\Set',
  27. 'setnx' => '\Predis\Commands\SetPreserve',
  28. 'setPreserve' => '\Predis\Commands\SetPreserve',
  29. 'mset' => '\Predis\Commands\SetMultiple',
  30. 'setMultiple' => '\Predis\Commands\SetMultiple',
  31. 'msetnx' => '\Predis\Commands\SetMultiplePreserve',
  32. 'setMultiplePreserve' => '\Predis\Commands\SetMultiplePreserve',
  33. 'get' => '\Predis\Commands\Get',
  34. 'mget' => '\Predis\Commands\GetMultiple',
  35. 'getMultiple' => '\Predis\Commands\GetMultiple',
  36. 'getset' => '\Predis\Commands\GetSet',
  37. 'getSet' => '\Predis\Commands\GetSet',
  38. 'incr' => '\Predis\Commands\Increment',
  39. 'increment' => '\Predis\Commands\Increment',
  40. 'incrby' => '\Predis\Commands\IncrementBy',
  41. 'incrementBy' => '\Predis\Commands\IncrementBy',
  42. 'decr' => '\Predis\Commands\Decrement',
  43. 'decrement' => '\Predis\Commands\Decrement',
  44. 'decrby' => '\Predis\Commands\DecrementBy',
  45. 'decrementBy' => '\Predis\Commands\DecrementBy',
  46. 'exists' => '\Predis\Commands\Exists',
  47. 'del' => '\Predis\Commands\Delete',
  48. 'delete' => '\Predis\Commands\Delete',
  49. 'type' => '\Predis\Commands\Type',
  50. /* commands operating on the key space */
  51. 'keys' => '\Predis\Commands\Keys',
  52. 'randomkey' => '\Predis\Commands\RandomKey',
  53. 'randomKey' => '\Predis\Commands\RandomKey',
  54. 'rename' => '\Predis\Commands\Rename',
  55. 'renamenx' => '\Predis\Commands\RenamePreserve',
  56. 'renamePreserve' => '\Predis\Commands\RenamePreserve',
  57. 'expire' => '\Predis\Commands\Expire',
  58. 'expireat' => '\Predis\Commands\ExpireAt',
  59. 'expireAt' => '\Predis\Commands\ExpireAt',
  60. 'dbsize' => '\Predis\Commands\DatabaseSize',
  61. 'databaseSize' => '\Predis\Commands\DatabaseSize',
  62. 'ttl' => '\Predis\Commands\TimeToLive',
  63. 'timeToLive' => '\Predis\Commands\TimeToLive',
  64. /* commands operating on lists */
  65. 'rpush' => '\Predis\Commands\ListPushTail',
  66. 'pushTail' => '\Predis\Commands\ListPushTail',
  67. 'lpush' => '\Predis\Commands\ListPushHead',
  68. 'pushHead' => '\Predis\Commands\ListPushHead',
  69. 'llen' => '\Predis\Commands\ListLength',
  70. 'listLength' => '\Predis\Commands\ListLength',
  71. 'lrange' => '\Predis\Commands\ListRange',
  72. 'listRange' => '\Predis\Commands\ListRange',
  73. 'ltrim' => '\Predis\Commands\ListTrim',
  74. 'listTrim' => '\Predis\Commands\ListTrim',
  75. 'lindex' => '\Predis\Commands\ListIndex',
  76. 'listIndex' => '\Predis\Commands\ListIndex',
  77. 'lset' => '\Predis\Commands\ListSet',
  78. 'listSet' => '\Predis\Commands\ListSet',
  79. 'lrem' => '\Predis\Commands\ListRemove',
  80. 'listRemove' => '\Predis\Commands\ListRemove',
  81. 'lpop' => '\Predis\Commands\ListPopFirst',
  82. 'popFirst' => '\Predis\Commands\ListPopFirst',
  83. 'rpop' => '\Predis\Commands\ListPopLast',
  84. 'popLast' => '\Predis\Commands\ListPopLast',
  85. 'rpoplpush' => '\Predis\Commands\ListPopLastPushHead',
  86. 'listPopLastPushHead' => '\Predis\Commands\ListPopLastPushHead',
  87. /* commands operating on sets */
  88. 'sadd' => '\Predis\Commands\SetAdd',
  89. 'setAdd' => '\Predis\Commands\SetAdd',
  90. 'srem' => '\Predis\Commands\SetRemove',
  91. 'setRemove' => '\Predis\Commands\SetRemove',
  92. 'spop' => '\Predis\Commands\SetPop',
  93. 'setPop' => '\Predis\Commands\SetPop',
  94. 'smove' => '\Predis\Commands\SetMove',
  95. 'setMove' => '\Predis\Commands\SetMove',
  96. 'scard' => '\Predis\Commands\SetCardinality',
  97. 'setCardinality' => '\Predis\Commands\SetCardinality',
  98. 'sismember' => '\Predis\Commands\SetIsMember',
  99. 'setIsMember' => '\Predis\Commands\SetIsMember',
  100. 'sinter' => '\Predis\Commands\SetIntersection',
  101. 'setIntersection' => '\Predis\Commands\SetIntersection',
  102. 'sinterstore' => '\Predis\Commands\SetIntersectionStore',
  103. 'setIntersectionStore' => '\Predis\Commands\SetIntersectionStore',
  104. 'sunion' => '\Predis\Commands\SetUnion',
  105. 'setUnion' => '\Predis\Commands\SetUnion',
  106. 'sunionstore' => '\Predis\Commands\SetUnionStore',
  107. 'setUnionStore' => '\Predis\Commands\SetUnionStore',
  108. 'sdiff' => '\Predis\Commands\SetDifference',
  109. 'setDifference' => '\Predis\Commands\SetDifference',
  110. 'sdiffstore' => '\Predis\Commands\SetDifferenceStore',
  111. 'setDifferenceStore' => '\Predis\Commands\SetDifferenceStore',
  112. 'smembers' => '\Predis\Commands\SetMembers',
  113. 'setMembers' => '\Predis\Commands\SetMembers',
  114. 'srandmember' => '\Predis\Commands\SetRandomMember',
  115. 'setRandomMember' => '\Predis\Commands\SetRandomMember',
  116. /* commands operating on sorted sets */
  117. 'zadd' => '\Predis\Commands\ZSetAdd',
  118. 'zsetAdd' => '\Predis\Commands\ZSetAdd',
  119. 'zincrby' => '\Predis\Commands\ZSetIncrementBy',
  120. 'zsetIncrementBy' => '\Predis\Commands\ZSetIncrementBy',
  121. 'zrem' => '\Predis\Commands\ZSetRemove',
  122. 'zsetRemove' => '\Predis\Commands\ZSetRemove',
  123. 'zrange' => '\Predis\Commands\ZSetRange',
  124. 'zsetRange' => '\Predis\Commands\ZSetRange',
  125. 'zrevrange' => '\Predis\Commands\ZSetReverseRange',
  126. 'zsetReverseRange' => '\Predis\Commands\ZSetReverseRange',
  127. 'zrangebyscore' => '\Predis\Commands\ZSetRangeByScore',
  128. 'zsetRangeByScore' => '\Predis\Commands\ZSetRangeByScore',
  129. 'zcard' => '\Predis\Commands\ZSetCardinality',
  130. 'zsetCardinality' => '\Predis\Commands\ZSetCardinality',
  131. 'zscore' => '\Predis\Commands\ZSetScore',
  132. 'zsetScore' => '\Predis\Commands\ZSetScore',
  133. 'zremrangebyscore' => '\Predis\Commands\ZSetRemoveRangeByScore',
  134. 'zsetRemoveRangeByScore' => '\Predis\Commands\ZSetRemoveRangeByScore',
  135. /* multiple databases handling commands */
  136. 'select' => '\Predis\Commands\SelectDatabase',
  137. 'selectDatabase' => '\Predis\Commands\SelectDatabase',
  138. 'move' => '\Predis\Commands\MoveKey',
  139. 'moveKey' => '\Predis\Commands\MoveKey',
  140. 'flushdb' => '\Predis\Commands\FlushDatabase',
  141. 'flushDatabase' => '\Predis\Commands\FlushDatabase',
  142. 'flushall' => '\Predis\Commands\FlushAll',
  143. 'flushDatabases' => '\Predis\Commands\FlushAll',
  144. /* sorting */
  145. 'sort' => '\Predis\Commands\Sort',
  146. /* remote server control commands */
  147. 'info' => '\Predis\Commands\Info',
  148. 'slaveof' => '\Predis\Commands\SlaveOf',
  149. 'slaveOf' => '\Predis\Commands\SlaveOf',
  150. /* persistence control commands */
  151. 'save' => '\Predis\Commands\Save',
  152. 'bgsave' => '\Predis\Commands\BackgroundSave',
  153. 'backgroundSave' => '\Predis\Commands\BackgroundSave',
  154. 'lastsave' => '\Predis\Commands\LastSave',
  155. 'lastSave' => '\Predis\Commands\LastSave',
  156. 'shutdown' => '\Predis\Commands\Shutdown',
  157. 'bgrewriteaof' => '\Predis\Commands\BackgroundRewriteAppendOnlyFile',
  158. 'backgroundRewriteAppendOnlyFile' => '\Predis\Commands\BackgroundRewriteAppendOnlyFile',
  159. );
  160. }
  161. }
  162. class RedisServer_LongNames_v2_0 extends RedisServer_LongNames_v1_2 {
  163. public function getVersion() { return '2.0'; }
  164. public function getSupportedCommands() {
  165. return array_merge(parent::getSupportedCommands(), array(
  166. /* transactions */
  167. 'multi' => '\Predis\Commands\Multi',
  168. 'exec' => '\Predis\Commands\Exec',
  169. 'discard' => '\Predis\Commands\Discard',
  170. /* commands operating on string values */
  171. 'setex' => '\Predis\Commands\SetExpire',
  172. 'setExpire' => '\Predis\Commands\SetExpire',
  173. 'append' => '\Predis\Commands\Append',
  174. 'substr' => '\Predis\Commands\Substr',
  175. /* commands operating on lists */
  176. 'blpop' => '\Predis\Commands\ListPopFirstBlocking',
  177. 'popFirstBlocking' => '\Predis\Commands\ListPopFirstBlocking',
  178. 'brpop' => '\Predis\Commands\ListPopLastBlocking',
  179. 'popLastBlocking' => '\Predis\Commands\ListPopLastBlocking',
  180. /* commands operating on sorted sets */
  181. 'zunionstore' => '\Predis\Commands\ZSetUnionStore',
  182. 'zsetUnionStore' => '\Predis\Commands\ZSetUnionStore',
  183. 'zinterstore' => '\Predis\Commands\ZSetIntersectionStore',
  184. 'zsetIntersectionStore' => '\Predis\Commands\ZSetIntersectionStore',
  185. 'zcount' => '\Predis\Commands\ZSetCount',
  186. 'zsetCount' => '\Predis\Commands\ZSetCount',
  187. 'zrank' => '\Predis\Commands\ZSetRank',
  188. 'zsetRank' => '\Predis\Commands\ZSetRank',
  189. 'zrevrank' => '\Predis\Commands\ZSetReverseRank',
  190. 'zsetReverseRank' => '\Predis\Commands\ZSetReverseRank',
  191. 'zremrangebyrank' => '\Predis\Commands\ZSetRemoveRangeByRank',
  192. 'zsetRemoveRangeByRank' => '\Predis\Commands\ZSetRemoveRangeByRank',
  193. /* commands operating on hashes */
  194. 'hset' => '\Predis\Commands\HashSet',
  195. 'hashSet' => '\Predis\Commands\HashSet',
  196. 'hsetnx' => '\Predis\Commands\HashSetPreserve',
  197. 'hashSetPreserve' => '\Predis\Commands\HashSetPreserve',
  198. 'hmset' => '\Predis\Commands\HashSetMultiple',
  199. 'hashSetMultiple' => '\Predis\Commands\HashSetMultiple',
  200. 'hincrby' => '\Predis\Commands\HashIncrementBy',
  201. 'hashIncrementBy' => '\Predis\Commands\HashIncrementBy',
  202. 'hget' => '\Predis\Commands\HashGet',
  203. 'hashGet' => '\Predis\Commands\HashGet',
  204. 'hmget' => '\Predis\Commands\HashGetMultiple',
  205. 'hashGetMultiple' => '\Predis\Commands\HashGetMultiple',
  206. 'hdel' => '\Predis\Commands\HashDelete',
  207. 'hashDelete' => '\Predis\Commands\HashDelete',
  208. 'hexists' => '\Predis\Commands\HashExists',
  209. 'hashExists' => '\Predis\Commands\HashExists',
  210. 'hlen' => '\Predis\Commands\HashLength',
  211. 'hashLength' => '\Predis\Commands\HashLength',
  212. 'hkeys' => '\Predis\Commands\HashKeys',
  213. 'hashKeys' => '\Predis\Commands\HashKeys',
  214. 'hvals' => '\Predis\Commands\HashValues',
  215. 'hashValues' => '\Predis\Commands\HashValues',
  216. 'hgetall' => '\Predis\Commands\HashGetAll',
  217. 'hashGetAll' => '\Predis\Commands\HashGetAll',
  218. /* publish - subscribe */
  219. 'subscribe' => '\Predis\Commands\Subscribe',
  220. 'unsubscribe' => '\Predis\Commands\Unsubscribe',
  221. 'psubscribe' => '\Predis\Commands\SubscribeByPattern',
  222. 'punsubscribe' => '\Predis\Commands\UnsubscribeByPattern',
  223. 'publish' => '\Predis\Commands\Publish',
  224. /* remote server control commands */
  225. 'config' => '\Predis\Commands\Config',
  226. 'configuration' => '\Predis\Commands\Config',
  227. ));
  228. }
  229. }
  230. /* ------------------------------------------------------------------------- */
  231. abstract class InlineCommand extends Command {
  232. public function serializeRequest($command, $arguments) {
  233. if (isset($arguments[0]) && is_array($arguments[0])) {
  234. $arguments[0] = implode($arguments[0], ' ');
  235. }
  236. return $command . (count($arguments) > 0
  237. ? ' ' . implode($arguments, ' ') . Protocol::NEWLINE
  238. : Protocol::NEWLINE
  239. );
  240. }
  241. }
  242. abstract class BulkCommand extends Command {
  243. public function serializeRequest($command, $arguments) {
  244. $data = array_pop($arguments);
  245. if (is_array($data)) {
  246. $data = implode($data, ' ');
  247. }
  248. return $command . ' ' . implode($arguments, ' ') . ' ' . strlen($data) .
  249. Protocol::NEWLINE . $data . Protocol::NEWLINE;
  250. }
  251. }
  252. class RedisServer_v1_0 extends \Predis\RedisServerProfile {
  253. public function getVersion() { return '1.0'; }
  254. public function getSupportedCommands() {
  255. return array(
  256. /* miscellaneous commands */
  257. 'ping' => '\Predis\Compatibility\v1_0\Commands\Ping',
  258. 'echo' => '\Predis\Compatibility\v1_0\Commands\DoEcho',
  259. 'auth' => '\Predis\Compatibility\v1_0\Commands\Auth',
  260. /* connection handling */
  261. 'quit' => '\Predis\Compatibility\v1_0\Commands\Quit',
  262. /* commands operating on string values */
  263. 'set' => '\Predis\Compatibility\v1_0\Commands\Set',
  264. 'setnx' => '\Predis\Compatibility\v1_0\Commands\SetPreserve',
  265. 'setPreserve' => '\Predis\Compatibility\v1_0\Commands\SetPreserve',
  266. 'get' => '\Predis\Compatibility\v1_0\Commands\Get',
  267. 'mget' => '\Predis\Compatibility\v1_0\Commands\GetMultiple',
  268. 'getMultiple' => '\Predis\Compatibility\v1_0\Commands\GetMultiple',
  269. 'getset' => '\Predis\Compatibility\v1_0\Commands\GetSet',
  270. 'getSet' => '\Predis\Compatibility\v1_0\Commands\GetSet',
  271. 'incr' => '\Predis\Compatibility\v1_0\Commands\Increment',
  272. 'increment' => '\Predis\Compatibility\v1_0\Commands\Increment',
  273. 'incrby' => '\Predis\Compatibility\v1_0\Commands\IncrementBy',
  274. 'incrementBy' => '\Predis\Compatibility\v1_0\Commands\IncrementBy',
  275. 'decr' => '\Predis\Compatibility\v1_0\Commands\Decrement',
  276. 'decrement' => '\Predis\Compatibility\v1_0\Commands\Decrement',
  277. 'decrby' => '\Predis\Compatibility\v1_0\Commands\DecrementBy',
  278. 'decrementBy' => '\Predis\Compatibility\v1_0\Commands\DecrementBy',
  279. 'exists' => '\Predis\Compatibility\v1_0\Commands\Exists',
  280. 'del' => '\Predis\Compatibility\v1_0\Commands\Delete',
  281. 'delete' => '\Predis\Compatibility\v1_0\Commands\Delete',
  282. 'type' => '\Predis\Compatibility\v1_0\Commands\Type',
  283. /* commands operating on the key space */
  284. 'keys' => '\Predis\Compatibility\v1_0\Commands\Keys',
  285. 'randomkey' => '\Predis\Compatibility\v1_0\Commands\RandomKey',
  286. 'randomKey' => '\Predis\Compatibility\v1_0\Commands\RandomKey',
  287. 'rename' => '\Predis\Compatibility\v1_0\Commands\Rename',
  288. 'renamenx' => '\Predis\Compatibility\v1_0\Commands\RenamePreserve',
  289. 'renamePreserve' => '\Predis\Compatibility\v1_0\Commands\RenamePreserve',
  290. 'expire' => '\Predis\Compatibility\v1_0\Commands\Expire',
  291. 'expireat' => '\Predis\Compatibility\v1_0\Commands\ExpireAt',
  292. 'expireAt' => '\Predis\Compatibility\v1_0\Commands\ExpireAt',
  293. 'dbsize' => '\Predis\Compatibility\v1_0\Commands\DatabaseSize',
  294. 'databaseSize' => '\Predis\Compatibility\v1_0\Commands\DatabaseSize',
  295. 'ttl' => '\Predis\Compatibility\v1_0\Commands\TimeToLive',
  296. 'timeToLive' => '\Predis\Compatibility\v1_0\Commands\TimeToLive',
  297. /* commands operating on lists */
  298. 'rpush' => '\Predis\Compatibility\v1_0\Commands\ListPushTail',
  299. 'pushTail' => '\Predis\Compatibility\v1_0\Commands\ListPushTail',
  300. 'lpush' => '\Predis\Compatibility\v1_0\Commands\ListPushHead',
  301. 'pushHead' => '\Predis\Compatibility\v1_0\Commands\ListPushHead',
  302. 'llen' => '\Predis\Compatibility\v1_0\Commands\ListLength',
  303. 'listLength' => '\Predis\Compatibility\v1_0\Commands\ListLength',
  304. 'lrange' => '\Predis\Compatibility\v1_0\Commands\ListRange',
  305. 'listRange' => '\Predis\Compatibility\v1_0\Commands\ListRange',
  306. 'ltrim' => '\Predis\Compatibility\v1_0\Commands\ListTrim',
  307. 'listTrim' => '\Predis\Compatibility\v1_0\Commands\ListTrim',
  308. 'lindex' => '\Predis\Compatibility\v1_0\Commands\ListIndex',
  309. 'listIndex' => '\Predis\Compatibility\v1_0\Commands\ListIndex',
  310. 'lset' => '\Predis\Compatibility\v1_0\Commands\ListSet',
  311. 'listSet' => '\Predis\Compatibility\v1_0\Commands\ListSet',
  312. 'lrem' => '\Predis\Compatibility\v1_0\Commands\ListRemove',
  313. 'listRemove' => '\Predis\Compatibility\v1_0\Commands\ListRemove',
  314. 'lpop' => '\Predis\Compatibility\v1_0\Commands\ListPopFirst',
  315. 'popFirst' => '\Predis\Compatibility\v1_0\Commands\ListPopFirst',
  316. 'rpop' => '\Predis\Compatibility\v1_0\Commands\ListPopLast',
  317. 'popLast' => '\Predis\Compatibility\v1_0\Commands\ListPopLast',
  318. /* commands operating on sets */
  319. 'sadd' => '\Predis\Compatibility\v1_0\Commands\SetAdd',
  320. 'setAdd' => '\Predis\Compatibility\v1_0\Commands\SetAdd',
  321. 'srem' => '\Predis\Compatibility\v1_0\Commands\SetRemove',
  322. 'setRemove' => '\Predis\Compatibility\v1_0\Commands\SetRemove',
  323. 'spop' => '\Predis\Compatibility\v1_0\Commands\SetPop',
  324. 'setPop' => '\Predis\Compatibility\v1_0\Commands\SetPop',
  325. 'smove' => '\Predis\Compatibility\v1_0\Commands\SetMove',
  326. 'setMove' => '\Predis\Compatibility\v1_0\Commands\SetMove',
  327. 'scard' => '\Predis\Compatibility\v1_0\Commands\SetCardinality',
  328. 'setCardinality' => '\Predis\Compatibility\v1_0\Commands\SetCardinality',
  329. 'sismember' => '\Predis\Compatibility\v1_0\Commands\SetIsMember',
  330. 'setIsMember' => '\Predis\Compatibility\v1_0\Commands\SetIsMember',
  331. 'sinter' => '\Predis\Compatibility\v1_0\Commands\SetIntersection',
  332. 'setIntersection' => '\Predis\Compatibility\v1_0\Commands\SetIntersection',
  333. 'sinterstore' => '\Predis\Compatibility\v1_0\Commands\SetIntersectionStore',
  334. 'setIntersectionStore' => '\Predis\Compatibility\v1_0\Commands\SetIntersectionStore',
  335. 'sunion' => '\Predis\Compatibility\v1_0\Commands\SetUnion',
  336. 'setUnion' => '\Predis\Compatibility\v1_0\Commands\SetUnion',
  337. 'sunionstore' => '\Predis\Compatibility\v1_0\Commands\SetUnionStore',
  338. 'setUnionStore' => '\Predis\Compatibility\v1_0\Commands\SetUnionStore',
  339. 'sdiff' => '\Predis\Compatibility\v1_0\Commands\SetDifference',
  340. 'setDifference' => '\Predis\Compatibility\v1_0\Commands\SetDifference',
  341. 'sdiffstore' => '\Predis\Compatibility\v1_0\Commands\SetDifferenceStore',
  342. 'setDifferenceStore' => '\Predis\Compatibility\v1_0\Commands\SetDifferenceStore',
  343. 'smembers' => '\Predis\Compatibility\v1_0\Commands\SetMembers',
  344. 'setMembers' => '\Predis\Compatibility\v1_0\Commands\SetMembers',
  345. 'srandmember' => '\Predis\Compatibility\v1_0\Commands\SetRandomMember',
  346. 'setRandomMember' => '\Predis\Compatibility\v1_0\Commands\SetRandomMember',
  347. /* multiple databases handling commands */
  348. 'select' => '\Predis\Compatibility\v1_0\Commands\SelectDatabase',
  349. 'selectDatabase' => '\Predis\Compatibility\v1_0\Commands\SelectDatabase',
  350. 'move' => '\Predis\Compatibility\v1_0\Commands\MoveKey',
  351. 'moveKey' => '\Predis\Compatibility\v1_0\Commands\MoveKey',
  352. 'flushdb' => '\Predis\Compatibility\v1_0\Commands\FlushDatabase',
  353. 'flushDatabase' => '\Predis\Compatibility\v1_0\Commands\FlushDatabase',
  354. 'flushall' => '\Predis\Compatibility\v1_0\Commands\FlushAll',
  355. 'flushDatabases' => '\Predis\Compatibility\v1_0\Commands\FlushAll',
  356. /* sorting */
  357. 'sort' => '\Predis\Compatibility\v1_0\Commands\Sort',
  358. /* remote server control commands */
  359. 'info' => '\Predis\Compatibility\v1_0\Commands\Info',
  360. 'slaveof' => '\Predis\Compatibility\v1_0\Commands\SlaveOf',
  361. 'slaveOf' => '\Predis\Compatibility\v1_0\Commands\SlaveOf',
  362. /* persistence control commands */
  363. 'save' => '\Predis\Compatibility\v1_0\Commands\Save',
  364. 'bgsave' => '\Predis\Compatibility\v1_0\Commands\BackgroundSave',
  365. 'backgroundSave' => '\Predis\Compatibility\v1_0\Commands\BackgroundSave',
  366. 'lastsave' => '\Predis\Compatibility\v1_0\Commands\LastSave',
  367. 'lastSave' => '\Predis\Compatibility\v1_0\Commands\LastSave',
  368. 'shutdown' => '\Predis\Compatibility\v1_0\Commands\Shutdown',
  369. );
  370. }
  371. }
  372. namespace Predis\Compatibility\v1_0\Commands;
  373. /* miscellaneous commands */
  374. class Ping extends \Predis\InlineCommand {
  375. public function canBeHashed() { return false; }
  376. public function getCommandId() { return 'PING'; }
  377. public function parseResponse($data) {
  378. return $data === 'PONG' ? true : false;
  379. }
  380. }
  381. class DoEcho extends \Predis\BulkCommand {
  382. public function canBeHashed() { return false; }
  383. public function getCommandId() { return 'ECHO'; }
  384. }
  385. class Auth extends \Predis\InlineCommand {
  386. public function canBeHashed() { return false; }
  387. public function getCommandId() { return 'AUTH'; }
  388. }
  389. /* connection handling */
  390. class Quit extends \Predis\InlineCommand {
  391. public function canBeHashed() { return false; }
  392. public function getCommandId() { return 'QUIT'; }
  393. public function closesConnection() { return true; }
  394. }
  395. /* commands operating on string values */
  396. class Set extends \Predis\BulkCommand {
  397. public function getCommandId() { return 'SET'; }
  398. }
  399. class SetPreserve extends \Predis\BulkCommand {
  400. public function getCommandId() { return 'SETNX'; }
  401. public function parseResponse($data) { return (bool) $data; }
  402. }
  403. class Get extends \Predis\InlineCommand {
  404. public function getCommandId() { return 'GET'; }
  405. }
  406. class GetMultiple extends \Predis\InlineCommand {
  407. public function canBeHashed() { return false; }
  408. public function getCommandId() { return 'MGET'; }
  409. }
  410. class GetSet extends \Predis\BulkCommand {
  411. public function getCommandId() { return 'GETSET'; }
  412. }
  413. class Increment extends \Predis\InlineCommand {
  414. public function getCommandId() { return 'INCR'; }
  415. }
  416. class IncrementBy extends \Predis\InlineCommand {
  417. public function getCommandId() { return 'INCRBY'; }
  418. }
  419. class Decrement extends \Predis\InlineCommand {
  420. public function getCommandId() { return 'DECR'; }
  421. }
  422. class DecrementBy extends \Predis\InlineCommand {
  423. public function getCommandId() { return 'DECRBY'; }
  424. }
  425. class Exists extends \Predis\InlineCommand {
  426. public function getCommandId() { return 'EXISTS'; }
  427. public function parseResponse($data) { return (bool) $data; }
  428. }
  429. class Delete extends \Predis\InlineCommand {
  430. public function getCommandId() { return 'DEL'; }
  431. }
  432. class Type extends \Predis\InlineCommand {
  433. public function getCommandId() { return 'TYPE'; }
  434. }
  435. /* commands operating on the key space */
  436. class Keys extends \Predis\InlineCommand {
  437. public function canBeHashed() { return false; }
  438. public function getCommandId() { return 'KEYS'; }
  439. public function parseResponse($data) {
  440. return strlen($data) > 0 ? explode(' ', $data) : array();
  441. }
  442. }
  443. class RandomKey extends \Predis\InlineCommand {
  444. public function canBeHashed() { return false; }
  445. public function getCommandId() { return 'RANDOMKEY'; }
  446. public function parseResponse($data) { return $data !== '' ? $data : null; }
  447. }
  448. class Rename extends \Predis\InlineCommand {
  449. public function canBeHashed() { return false; }
  450. public function getCommandId() { return 'RENAME'; }
  451. }
  452. class RenamePreserve extends \Predis\InlineCommand {
  453. public function canBeHashed() { return false; }
  454. public function getCommandId() { return 'RENAMENX'; }
  455. public function parseResponse($data) { return (bool) $data; }
  456. }
  457. class Expire extends \Predis\InlineCommand {
  458. public function getCommandId() { return 'EXPIRE'; }
  459. public function parseResponse($data) { return (bool) $data; }
  460. }
  461. class ExpireAt extends \Predis\InlineCommand {
  462. public function getCommandId() { return 'EXPIREAT'; }
  463. public function parseResponse($data) { return (bool) $data; }
  464. }
  465. class DatabaseSize extends \Predis\InlineCommand {
  466. public function canBeHashed() { return false; }
  467. public function getCommandId() { return 'DBSIZE'; }
  468. }
  469. class TimeToLive extends \Predis\InlineCommand {
  470. public function getCommandId() { return 'TTL'; }
  471. }
  472. /* commands operating on lists */
  473. class ListPushTail extends \Predis\BulkCommand {
  474. public function getCommandId() { return 'RPUSH'; }
  475. }
  476. class ListPushHead extends \Predis\BulkCommand {
  477. public function getCommandId() { return 'LPUSH'; }
  478. }
  479. class ListLength extends \Predis\InlineCommand {
  480. public function getCommandId() { return 'LLEN'; }
  481. }
  482. class ListRange extends \Predis\InlineCommand {
  483. public function getCommandId() { return 'LRANGE'; }
  484. }
  485. class ListTrim extends \Predis\InlineCommand {
  486. public function getCommandId() { return 'LTRIM'; }
  487. }
  488. class ListIndex extends \Predis\InlineCommand {
  489. public function getCommandId() { return 'LINDEX'; }
  490. }
  491. class ListSet extends \Predis\BulkCommand {
  492. public function getCommandId() { return 'LSET'; }
  493. }
  494. class ListRemove extends \Predis\BulkCommand {
  495. public function getCommandId() { return 'LREM'; }
  496. }
  497. class ListPopFirst extends \Predis\InlineCommand {
  498. public function getCommandId() { return 'LPOP'; }
  499. }
  500. class ListPopLast extends \Predis\InlineCommand {
  501. public function getCommandId() { return 'RPOP'; }
  502. }
  503. /* commands operating on sets */
  504. class SetAdd extends \Predis\BulkCommand {
  505. public function getCommandId() { return 'SADD'; }
  506. public function parseResponse($data) { return (bool) $data; }
  507. }
  508. class SetRemove extends \Predis\BulkCommand {
  509. public function getCommandId() { return 'SREM'; }
  510. public function parseResponse($data) { return (bool) $data; }
  511. }
  512. class SetPop extends \Predis\InlineCommand {
  513. public function getCommandId() { return 'SPOP'; }
  514. }
  515. class SetMove extends \Predis\BulkCommand {
  516. public function canBeHashed() { return false; }
  517. public function getCommandId() { return 'SMOVE'; }
  518. public function parseResponse($data) { return (bool) $data; }
  519. }
  520. class SetCardinality extends \Predis\InlineCommand {
  521. public function getCommandId() { return 'SCARD'; }
  522. }
  523. class SetIsMember extends \Predis\BulkCommand {
  524. public function getCommandId() { return 'SISMEMBER'; }
  525. public function parseResponse($data) { return (bool) $data; }
  526. }
  527. class SetIntersection extends \Predis\InlineCommand {
  528. public function getCommandId() { return 'SINTER'; }
  529. }
  530. class SetIntersectionStore extends \Predis\InlineCommand {
  531. public function getCommandId() { return 'SINTERSTORE'; }
  532. }
  533. class SetUnion extends \Predis\InlineCommand {
  534. public function getCommandId() { return 'SUNION'; }
  535. }
  536. class SetUnionStore extends \Predis\InlineCommand {
  537. public function getCommandId() { return 'SUNIONSTORE'; }
  538. }
  539. class SetDifference extends \Predis\InlineCommand {
  540. public function getCommandId() { return 'SDIFF'; }
  541. }
  542. class SetDifferenceStore extends \Predis\InlineCommand {
  543. public function getCommandId() { return 'SDIFFSTORE'; }
  544. }
  545. class SetMembers extends \Predis\InlineCommand {
  546. public function getCommandId() { return 'SMEMBERS'; }
  547. }
  548. class SetRandomMember extends \Predis\InlineCommand {
  549. public function getCommandId() { return 'SRANDMEMBER'; }
  550. }
  551. /* multiple databases handling commands */
  552. class SelectDatabase extends \Predis\InlineCommand {
  553. public function canBeHashed() { return false; }
  554. public function getCommandId() { return 'SELECT'; }
  555. }
  556. class MoveKey extends \Predis\InlineCommand {
  557. public function canBeHashed() { return false; }
  558. public function getCommandId() { return 'MOVE'; }
  559. public function parseResponse($data) { return (bool) $data; }
  560. }
  561. class FlushDatabase extends \Predis\InlineCommand {
  562. public function canBeHashed() { return false; }
  563. public function getCommandId() { return 'FLUSHDB'; }
  564. }
  565. class FlushAll extends \Predis\InlineCommand {
  566. public function canBeHashed() { return false; }
  567. public function getCommandId() { return 'FLUSHALL'; }
  568. }
  569. /* sorting */
  570. class Sort extends \Predis\InlineCommand {
  571. public function getCommandId() { return 'SORT'; }
  572. public function filterArguments(Array $arguments) {
  573. if (count($arguments) === 1) {
  574. return $arguments;
  575. }
  576. // TODO: add more parameters checks
  577. $query = array($arguments[0]);
  578. $sortParams = $arguments[1];
  579. if (isset($sortParams['by'])) {
  580. $query[] = 'BY';
  581. $query[] = $sortParams['by'];
  582. }
  583. if (isset($sortParams['get'])) {
  584. $getargs = $sortParams['get'];
  585. if (is_array($getargs)) {
  586. foreach ($getargs as $getarg) {
  587. $query[] = 'GET';
  588. $query[] = $getarg;
  589. }
  590. }
  591. else {
  592. $query[] = 'GET';
  593. $query[] = $getargs;
  594. }
  595. }
  596. if (isset($sortParams['limit']) && is_array($sortParams['limit'])) {
  597. $query[] = 'LIMIT';
  598. $query[] = $sortParams['limit'][0];
  599. $query[] = $sortParams['limit'][1];
  600. }
  601. if (isset($sortParams['sort'])) {
  602. $query[] = strtoupper($sortParams['sort']);
  603. }
  604. if (isset($sortParams['alpha']) && $sortParams['alpha'] == true) {
  605. $query[] = 'ALPHA';
  606. }
  607. if (isset($sortParams['store']) && $sortParams['store'] == true) {
  608. $query[] = 'STORE';
  609. $query[] = $sortParams['store'];
  610. }
  611. return $query;
  612. }
  613. }
  614. /* persistence control commands */
  615. class Save extends \Predis\InlineCommand {
  616. public function canBeHashed() { return false; }
  617. public function getCommandId() { return 'SAVE'; }
  618. }
  619. class BackgroundSave extends \Predis\InlineCommand {
  620. public function canBeHashed() { return false; }
  621. public function getCommandId() { return 'BGSAVE'; }
  622. public function parseResponse($data) {
  623. if ($data == 'Background saving started') {
  624. return true;
  625. }
  626. return $data;
  627. }
  628. }
  629. class LastSave extends \Predis\InlineCommand {
  630. public function canBeHashed() { return false; }
  631. public function getCommandId() { return 'LASTSAVE'; }
  632. }
  633. class Shutdown extends \Predis\InlineCommand {
  634. public function canBeHashed() { return false; }
  635. public function getCommandId() { return 'SHUTDOWN'; }
  636. public function closesConnection() { return true; }
  637. }
  638. /* remote server control commands */
  639. class Info extends \Predis\InlineCommand {
  640. public function canBeHashed() { return false; }
  641. public function getCommandId() { return 'INFO'; }
  642. public function parseResponse($data) {
  643. $info = array();
  644. $infoLines = explode("\r\n", $data, -1);
  645. foreach ($infoLines as $row) {
  646. list($k, $v) = explode(':', $row);
  647. if (!preg_match('/^db\d+$/', $k)) {
  648. $info[$k] = $v;
  649. }
  650. else {
  651. $db = array();
  652. foreach (explode(',', $v) as $dbvar) {
  653. list($dbvk, $dbvv) = explode('=', $dbvar);
  654. $db[trim($dbvk)] = $dbvv;
  655. }
  656. $info[$k] = $db;
  657. }
  658. }
  659. return $info;
  660. }
  661. }
  662. class SlaveOf extends \Predis\InlineCommand {
  663. public function canBeHashed() { return false; }
  664. public function getCommandId() { return 'SLAVEOF'; }
  665. public function filterArguments(Array $arguments) {
  666. if (count($arguments) === 0 || $arguments[0] === 'NO ONE') {
  667. return array('NO', 'ONE');
  668. }
  669. return $arguments;
  670. }
  671. }
  672. ?>