Predis_Compatibility.php 35 KB

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