Predis_Compatibility.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <?php
  2. Predis_RedisServerProfile::registerProfile('Predis_RedisServer_v1_0', '1.0');
  3. Predis_RedisServerProfile::registerProfile('Predis_RedisServer_v1_2_LongNames', '1.2');
  4. Predis_RedisServerProfile::registerProfile('Predis_RedisServer_v2_0_LongNames', '2.0');
  5. class Predis_RedisServer_v1_0 extends Predis_RedisServerProfile {
  6. public function getVersion() { return '1.0'; }
  7. public function getSupportedCommands() {
  8. return array(
  9. /* miscellaneous commands */
  10. 'ping' => 'Predis_Compatibility_v1_0_Commands_Ping',
  11. 'echo' => 'Predis_Compatibility_v1_0_Commands_DoEcho',
  12. 'auth' => 'Predis_Compatibility_v1_0_Commands_Auth',
  13. /* connection handling */
  14. 'quit' => 'Predis_Compatibility_v1_0_Commands_Quit',
  15. /* commands operating on string values */
  16. 'set' => 'Predis_Compatibility_v1_0_Commands_Set',
  17. 'setnx' => 'Predis_Compatibility_v1_0_Commands_SetPreserve',
  18. 'setPreserve' => 'Predis_Compatibility_v1_0_Commands_SetPreserve',
  19. 'get' => 'Predis_Compatibility_v1_0_Commands_Get',
  20. 'mget' => 'Predis_Compatibility_v1_0_Commands_GetMultiple',
  21. 'getMultiple' => 'Predis_Compatibility_v1_0_Commands_GetMultiple',
  22. 'getset' => 'Predis_Compatibility_v1_0_Commands_GetSet',
  23. 'getSet' => 'Predis_Compatibility_v1_0_Commands_GetSet',
  24. 'incr' => 'Predis_Compatibility_v1_0_Commands_Increment',
  25. 'increment' => 'Predis_Compatibility_v1_0_Commands_Increment',
  26. 'incrby' => 'Predis_Compatibility_v1_0_Commands_IncrementBy',
  27. 'incrementBy' => 'Predis_Compatibility_v1_0_Commands_IncrementBy',
  28. 'decr' => 'Predis_Compatibility_v1_0_Commands_Decrement',
  29. 'decrement' => 'Predis_Compatibility_v1_0_Commands_Decrement',
  30. 'decrby' => 'Predis_Compatibility_v1_0_Commands_DecrementBy',
  31. 'decrementBy' => 'Predis_Compatibility_v1_0_Commands_DecrementBy',
  32. 'exists' => 'Predis_Compatibility_v1_0_Commands_Exists',
  33. 'del' => 'Predis_Compatibility_v1_0_Commands_Delete',
  34. 'delete' => 'Predis_Compatibility_v1_0_Commands_Delete',
  35. 'type' => 'Predis_Compatibility_v1_0_Commands_Type',
  36. /* commands operating on the key space */
  37. 'keys' => 'Predis_Compatibility_v1_0_Commands_Keys',
  38. 'randomkey' => 'Predis_Compatibility_v1_0_Commands_RandomKey',
  39. 'randomKey' => 'Predis_Compatibility_v1_0_Commands_RandomKey',
  40. 'rename' => 'Predis_Compatibility_v1_0_Commands_Rename',
  41. 'renamenx' => 'Predis_Compatibility_v1_0_Commands_RenamePreserve',
  42. 'renamePreserve' => 'Predis_Compatibility_v1_0_Commands_RenamePreserve',
  43. 'expire' => 'Predis_Compatibility_v1_0_Commands_Expire',
  44. 'expireat' => 'Predis_Compatibility_v1_0_Commands_ExpireAt',
  45. 'expireAt' => 'Predis_Compatibility_v1_0_Commands_ExpireAt',
  46. 'dbsize' => 'Predis_Compatibility_v1_0_Commands_DatabaseSize',
  47. 'databaseSize' => 'Predis_Compatibility_v1_0_Commands_DatabaseSize',
  48. 'ttl' => 'Predis_Compatibility_v1_0_Commands_TimeToLive',
  49. 'timeToLive' => 'Predis_Compatibility_v1_0_Commands_TimeToLive',
  50. /* commands operating on lists */
  51. 'rpush' => 'Predis_Compatibility_v1_0_Commands_ListPushTail',
  52. 'pushTail' => 'Predis_Compatibility_v1_0_Commands_ListPushTail',
  53. 'lpush' => 'Predis_Compatibility_v1_0_Commands_ListPushHead',
  54. 'pushHead' => 'Predis_Compatibility_v1_0_Commands_ListPushHead',
  55. 'llen' => 'Predis_Compatibility_v1_0_Commands_ListLength',
  56. 'listLength' => 'Predis_Compatibility_v1_0_Commands_ListLength',
  57. 'lrange' => 'Predis_Compatibility_v1_0_Commands_ListRange',
  58. 'listRange' => 'Predis_Compatibility_v1_0_Commands_ListRange',
  59. 'ltrim' => 'Predis_Compatibility_v1_0_Commands_ListTrim',
  60. 'listTrim' => 'Predis_Compatibility_v1_0_Commands_ListTrim',
  61. 'lindex' => 'Predis_Compatibility_v1_0_Commands_ListIndex',
  62. 'listIndex' => 'Predis_Compatibility_v1_0_Commands_ListIndex',
  63. 'lset' => 'Predis_Compatibility_v1_0_Commands_ListSet',
  64. 'listSet' => 'Predis_Compatibility_v1_0_Commands_ListSet',
  65. 'lrem' => 'Predis_Compatibility_v1_0_Commands_ListRemove',
  66. 'listRemove' => 'Predis_Compatibility_v1_0_Commands_ListRemove',
  67. 'lpop' => 'Predis_Compatibility_v1_0_Commands_ListPopFirst',
  68. 'popFirst' => 'Predis_Compatibility_v1_0_Commands_ListPopFirst',
  69. 'rpop' => 'Predis_Compatibility_v1_0_Commands_ListPopLast',
  70. 'popLast' => 'Predis_Compatibility_v1_0_Commands_ListPopLast',
  71. /* commands operating on sets */
  72. 'sadd' => 'Predis_Compatibility_v1_0_Commands_SetAdd',
  73. 'setAdd' => 'Predis_Compatibility_v1_0_Commands_SetAdd',
  74. 'srem' => 'Predis_Compatibility_v1_0_Commands_SetRemove',
  75. 'setRemove' => 'Predis_Compatibility_v1_0_Commands_SetRemove',
  76. 'spop' => 'Predis_Compatibility_v1_0_Commands_SetPop',
  77. 'setPop' => 'Predis_Compatibility_v1_0_Commands_SetPop',
  78. 'smove' => 'Predis_Compatibility_v1_0_Commands_SetMove',
  79. 'setMove' => 'Predis_Compatibility_v1_0_Commands_SetMove',
  80. 'scard' => 'Predis_Compatibility_v1_0_Commands_SetCardinality',
  81. 'setCardinality' => 'Predis_Compatibility_v1_0_Commands_SetCardinality',
  82. 'sismember' => 'Predis_Compatibility_v1_0_Commands_SetIsMember',
  83. 'setIsMember' => 'Predis_Compatibility_v1_0_Commands_SetIsMember',
  84. 'sinter' => 'Predis_Compatibility_v1_0_Commands_SetIntersection',
  85. 'setIntersection' => 'Predis_Compatibility_v1_0_Commands_SetIntersection',
  86. 'sinterstore' => 'Predis_Compatibility_v1_0_Commands_SetIntersectionStore',
  87. 'setIntersectionStore' => 'Predis_Compatibility_v1_0_Commands_SetIntersectionStore',
  88. 'sunion' => 'Predis_Compatibility_v1_0_Commands_SetUnion',
  89. 'setUnion' => 'Predis_Compatibility_v1_0_Commands_SetUnion',
  90. 'sunionstore' => 'Predis_Compatibility_v1_0_Commands_SetUnionStore',
  91. 'setUnionStore' => 'Predis_Compatibility_v1_0_Commands_SetUnionStore',
  92. 'sdiff' => 'Predis_Compatibility_v1_0_Commands_SetDifference',
  93. 'setDifference' => 'Predis_Compatibility_v1_0_Commands_SetDifference',
  94. 'sdiffstore' => 'Predis_Compatibility_v1_0_Commands_SetDifferenceStore',
  95. 'setDifferenceStore' => 'Predis_Compatibility_v1_0_Commands_SetDifferenceStore',
  96. 'smembers' => 'Predis_Compatibility_v1_0_Commands_SetMembers',
  97. 'setMembers' => 'Predis_Compatibility_v1_0_Commands_SetMembers',
  98. 'srandmember' => 'Predis_Compatibility_v1_0_Commands_SetRandomMember',
  99. 'setRandomMember' => 'Predis_Compatibility_v1_0_Commands_SetRandomMember',
  100. /* multiple databases handling commands */
  101. 'select' => 'Predis_Compatibility_v1_0_Commands_SelectDatabase',
  102. 'selectDatabase' => 'Predis_Compatibility_v1_0_Commands_SelectDatabase',
  103. 'move' => 'Predis_Compatibility_v1_0_Commands_MoveKey',
  104. 'moveKey' => 'Predis_Compatibility_v1_0_Commands_MoveKey',
  105. 'flushdb' => 'Predis_Compatibility_v1_0_Commands_FlushDatabase',
  106. 'flushDatabase' => 'Predis_Compatibility_v1_0_Commands_FlushDatabase',
  107. 'flushall' => 'Predis_Compatibility_v1_0_Commands_FlushAll',
  108. 'flushDatabases' => 'Predis_Compatibility_v1_0_Commands_FlushAll',
  109. /* sorting */
  110. 'sort' => 'Predis_Compatibility_v1_0_Commands_Sort',
  111. /* remote server control commands */
  112. 'info' => 'Predis_Compatibility_v1_0_Commands_Info',
  113. 'slaveof' => 'Predis_Compatibility_v1_0_Commands_SlaveOf',
  114. 'slaveOf' => 'Predis_Compatibility_v1_0_Commands_SlaveOf',
  115. /* persistence control commands */
  116. 'save' => 'Predis_Compatibility_v1_0_Commands_Save',
  117. 'bgsave' => 'Predis_Compatibility_v1_0_Commands_BackgroundSave',
  118. 'backgroundSave' => 'Predis_Compatibility_v1_0_Commands_BackgroundSave',
  119. 'lastsave' => 'Predis_Compatibility_v1_0_Commands_LastSave',
  120. 'lastSave' => 'Predis_Compatibility_v1_0_Commands_LastSave',
  121. 'shutdown' => 'Predis_Compatibility_v1_0_Commands_Shutdown',
  122. );
  123. }
  124. }
  125. class Predis_RedisServer_v1_2_LongNames extends Predis_RedisServerProfile {
  126. public function getVersion() { return '1.2'; }
  127. public function getSupportedCommands() {
  128. return array(
  129. /* miscellaneous commands */
  130. 'ping' => 'Predis_Commands_Ping',
  131. 'echo' => 'Predis_Commands_DoEcho',
  132. 'auth' => 'Predis_Commands_Auth',
  133. /* connection handling */
  134. 'quit' => 'Predis_Commands_Quit',
  135. /* commands operating on string values */
  136. 'set' => 'Predis_Commands_Set',
  137. 'setnx' => 'Predis_Commands_SetPreserve',
  138. 'setPreserve' => 'Predis_Commands_SetPreserve',
  139. 'mset' => 'Predis_Commands_SetMultiple',
  140. 'setMultiple' => 'Predis_Commands_SetMultiple',
  141. 'msetnx' => 'Predis_Commands_SetMultiplePreserve',
  142. 'setMultiplePreserve' => 'Predis_Commands_SetMultiplePreserve',
  143. 'get' => 'Predis_Commands_Get',
  144. 'mget' => 'Predis_Commands_GetMultiple',
  145. 'getMultiple' => 'Predis_Commands_GetMultiple',
  146. 'getset' => 'Predis_Commands_GetSet',
  147. 'getSet' => 'Predis_Commands_GetSet',
  148. 'incr' => 'Predis_Commands_Increment',
  149. 'increment' => 'Predis_Commands_Increment',
  150. 'incrby' => 'Predis_Commands_IncrementBy',
  151. 'incrementBy' => 'Predis_Commands_IncrementBy',
  152. 'decr' => 'Predis_Commands_Decrement',
  153. 'decrement' => 'Predis_Commands_Decrement',
  154. 'decrby' => 'Predis_Commands_DecrementBy',
  155. 'decrementBy' => 'Predis_Commands_DecrementBy',
  156. 'exists' => 'Predis_Commands_Exists',
  157. 'del' => 'Predis_Commands_Delete',
  158. 'delete' => 'Predis_Commands_Delete',
  159. 'type' => 'Predis_Commands_Type',
  160. /* commands operating on the key space */
  161. 'keys' => 'Predis_Commands_Keys_v1_2',
  162. 'randomkey' => 'Predis_Commands_RandomKey',
  163. 'randomKey' => 'Predis_Commands_RandomKey',
  164. 'rename' => 'Predis_Commands_Rename',
  165. 'renamenx' => 'Predis_Commands_RenamePreserve',
  166. 'renamePreserve' => 'Predis_Commands_RenamePreserve',
  167. 'expire' => 'Predis_Commands_Expire',
  168. 'expireat' => 'Predis_Commands_ExpireAt',
  169. 'expireAt' => 'Predis_Commands_ExpireAt',
  170. 'dbsize' => 'Predis_Commands_DatabaseSize',
  171. 'databaseSize' => 'Predis_Commands_DatabaseSize',
  172. 'ttl' => 'Predis_Commands_TimeToLive',
  173. 'timeToLive' => 'Predis_Commands_TimeToLive',
  174. /* commands operating on lists */
  175. 'rpush' => 'Predis_Commands_ListPushTail',
  176. 'pushTail' => 'Predis_Commands_ListPushTail',
  177. 'lpush' => 'Predis_Commands_ListPushHead',
  178. 'pushHead' => 'Predis_Commands_ListPushHead',
  179. 'llen' => 'Predis_Commands_ListLength',
  180. 'listLength' => 'Predis_Commands_ListLength',
  181. 'lrange' => 'Predis_Commands_ListRange',
  182. 'listRange' => 'Predis_Commands_ListRange',
  183. 'ltrim' => 'Predis_Commands_ListTrim',
  184. 'listTrim' => 'Predis_Commands_ListTrim',
  185. 'lindex' => 'Predis_Commands_ListIndex',
  186. 'listIndex' => 'Predis_Commands_ListIndex',
  187. 'lset' => 'Predis_Commands_ListSet',
  188. 'listSet' => 'Predis_Commands_ListSet',
  189. 'lrem' => 'Predis_Commands_ListRemove',
  190. 'listRemove' => 'Predis_Commands_ListRemove',
  191. 'lpop' => 'Predis_Commands_ListPopFirst',
  192. 'popFirst' => 'Predis_Commands_ListPopFirst',
  193. 'rpop' => 'Predis_Commands_ListPopLast',
  194. 'popLast' => 'Predis_Commands_ListPopLast',
  195. 'rpoplpush' => 'Predis_Commands_ListPopLastPushHead',
  196. 'listPopLastPushHead' => 'Predis_Commands_ListPopLastPushHead',
  197. /* commands operating on sets */
  198. 'sadd' => 'Predis_Commands_SetAdd',
  199. 'setAdd' => 'Predis_Commands_SetAdd',
  200. 'srem' => 'Predis_Commands_SetRemove',
  201. 'setRemove' => 'Predis_Commands_SetRemove',
  202. 'spop' => 'Predis_Commands_SetPop',
  203. 'setPop' => 'Predis_Commands_SetPop',
  204. 'smove' => 'Predis_Commands_SetMove',
  205. 'setMove' => 'Predis_Commands_SetMove',
  206. 'scard' => 'Predis_Commands_SetCardinality',
  207. 'setCardinality' => 'Predis_Commands_SetCardinality',
  208. 'sismember' => 'Predis_Commands_SetIsMember',
  209. 'setIsMember' => 'Predis_Commands_SetIsMember',
  210. 'sinter' => 'Predis_Commands_SetIntersection',
  211. 'setIntersection' => 'Predis_Commands_SetIntersection',
  212. 'sinterstore' => 'Predis_Commands_SetIntersectionStore',
  213. 'setIntersectionStore' => 'Predis_Commands_SetIntersectionStore',
  214. 'sunion' => 'Predis_Commands_SetUnion',
  215. 'setUnion' => 'Predis_Commands_SetUnion',
  216. 'sunionstore' => 'Predis_Commands_SetUnionStore',
  217. 'setUnionStore' => 'Predis_Commands_SetUnionStore',
  218. 'sdiff' => 'Predis_Commands_SetDifference',
  219. 'setDifference' => 'Predis_Commands_SetDifference',
  220. 'sdiffstore' => 'Predis_Commands_SetDifferenceStore',
  221. 'setDifferenceStore' => 'Predis_Commands_SetDifferenceStore',
  222. 'smembers' => 'Predis_Commands_SetMembers',
  223. 'setMembers' => 'Predis_Commands_SetMembers',
  224. 'srandmember' => 'Predis_Commands_SetRandomMember',
  225. 'setRandomMember' => 'Predis_Commands_SetRandomMember',
  226. /* commands operating on sorted sets */
  227. 'zadd' => 'Predis_Commands_ZSetAdd',
  228. 'zsetAdd' => 'Predis_Commands_ZSetAdd',
  229. 'zincrby' => 'Predis_Commands_ZSetIncrementBy',
  230. 'zsetIncrementBy' => 'Predis_Commands_ZSetIncrementBy',
  231. 'zrem' => 'Predis_Commands_ZSetRemove',
  232. 'zsetRemove' => 'Predis_Commands_ZSetRemove',
  233. 'zrange' => 'Predis_Commands_ZSetRange',
  234. 'zsetRange' => 'Predis_Commands_ZSetRange',
  235. 'zrevrange' => 'Predis_Commands_ZSetReverseRange',
  236. 'zsetReverseRange' => 'Predis_Commands_ZSetReverseRange',
  237. 'zrangebyscore' => 'Predis_Commands_ZSetRangeByScore',
  238. 'zsetRangeByScore' => 'Predis_Commands_ZSetRangeByScore',
  239. 'zcard' => 'Predis_Commands_ZSetCardinality',
  240. 'zsetCardinality' => 'Predis_Commands_ZSetCardinality',
  241. 'zscore' => 'Predis_Commands_ZSetScore',
  242. 'zsetScore' => 'Predis_Commands_ZSetScore',
  243. 'zremrangebyscore' => 'Predis_Commands_ZSetRemoveRangeByScore',
  244. 'zsetRemoveRangeByScore' => 'Predis_Commands_ZSetRemoveRangeByScore',
  245. /* multiple databases handling commands */
  246. 'select' => 'Predis_Commands_SelectDatabase',
  247. 'selectDatabase' => 'Predis_Commands_SelectDatabase',
  248. 'move' => 'Predis_Commands_MoveKey',
  249. 'moveKey' => 'Predis_Commands_MoveKey',
  250. 'flushdb' => 'Predis_Commands_FlushDatabase',
  251. 'flushDatabase' => 'Predis_Commands_FlushDatabase',
  252. 'flushall' => 'Predis_Commands_FlushAll',
  253. 'flushDatabases' => 'Predis_Commands_FlushAll',
  254. /* sorting */
  255. 'sort' => 'Predis_Commands_Sort',
  256. /* remote server control commands */
  257. 'info' => 'Predis_Commands_Info',
  258. 'slaveof' => 'Predis_Commands_SlaveOf',
  259. 'slaveOf' => 'Predis_Commands_SlaveOf',
  260. /* persistence control commands */
  261. 'save' => 'Predis_Commands_Save',
  262. 'bgsave' => 'Predis_Commands_BackgroundSave',
  263. 'backgroundSave' => 'Predis_Commands_BackgroundSave',
  264. 'lastsave' => 'Predis_Commands_LastSave',
  265. 'lastSave' => 'Predis_Commands_LastSave',
  266. 'shutdown' => 'Predis_Commands_Shutdown',
  267. 'bgrewriteaof' => 'Predis_Commands_BackgroundRewriteAppendOnlyFile',
  268. 'backgroundRewriteAppendOnlyFile' => 'Predis_Commands_BackgroundRewriteAppendOnlyFile',
  269. );
  270. }
  271. }
  272. class Predis_RedisServer_v2_0_LongNames extends Predis_RedisServer_v1_2_LongNames {
  273. public function getVersion() { return '2.0'; }
  274. public function getSupportedCommands() {
  275. return array_merge(parent::getSupportedCommands(), array(
  276. /* transactions */
  277. 'multi' => 'Predis_Commands_Multi',
  278. 'exec' => 'Predis_Commands_Exec',
  279. 'discard' => 'Predis_Commands_Discard',
  280. /* commands operating on string values */
  281. 'setex' => 'Predis_Commands_SetExpire',
  282. 'setExpire' => 'Predis_Commands_SetExpire',
  283. 'append' => 'Predis_Commands_Append',
  284. 'substr' => 'Predis_Commands_Substr',
  285. /* commands operating on the key space */
  286. 'keys' => 'Predis_Commands_Keys',
  287. /* commands operating on lists */
  288. 'blpop' => 'Predis_Commands_ListPopFirstBlocking',
  289. 'popFirstBlocking' => 'Predis_Commands_ListPopFirstBlocking',
  290. 'brpop' => 'Predis_Commands_ListPopLastBlocking',
  291. 'popLastBlocking' => 'Predis_Commands_ListPopLastBlocking',
  292. /* commands operating on sorted sets */
  293. 'zunionstore' => 'Predis_Commands_ZSetUnionStore',
  294. 'zsetUnionStore' => 'Predis_Commands_ZSetUnionStore',
  295. 'zinterstore' => 'Predis_Commands_ZSetIntersectionStore',
  296. 'zsetIntersectionStore' => 'Predis_Commands_ZSetIntersectionStore',
  297. 'zcount' => 'Predis_Commands_ZSetCount',
  298. 'zsetCount' => 'Predis_Commands_ZSetCount',
  299. 'zrank' => 'Predis_Commands_ZSetRank',
  300. 'zsetRank' => 'Predis_Commands_ZSetRank',
  301. 'zrevrank' => 'Predis_Commands_ZSetReverseRank',
  302. 'zsetReverseRank' => 'Predis_Commands_ZSetReverseRank',
  303. 'zremrangebyrank' => 'Predis_Commands_ZSetRemoveRangeByRank',
  304. 'zsetRemoveRangeByRank' => 'Predis_Commands_ZSetRemoveRangeByRank',
  305. /* commands operating on hashes */
  306. 'hset' => 'Predis_Commands_HashSet',
  307. 'hashSet' => 'Predis_Commands_HashSet',
  308. 'hsetnx' => 'Predis_Commands_HashSetPreserve',
  309. 'hashSetPreserve' => 'Predis_Commands_HashSetPreserve',
  310. 'hmset' => 'Predis_Commands_HashSetMultiple',
  311. 'hashSetMultiple' => 'Predis_Commands_HashSetMultiple',
  312. 'hincrby' => 'Predis_Commands_HashIncrementBy',
  313. 'hashIncrementBy' => 'Predis_Commands_HashIncrementBy',
  314. 'hget' => 'Predis_Commands_HashGet',
  315. 'hashGet' => 'Predis_Commands_HashGet',
  316. 'hmget' => 'Predis_Commands_HashGetMultiple',
  317. 'hashGetMultiple' => 'Predis_Commands_HashGetMultiple',
  318. 'hdel' => 'Predis_Commands_HashDelete',
  319. 'hashDelete' => 'Predis_Commands_HashDelete',
  320. 'hexists' => 'Predis_Commands_HashExists',
  321. 'hashExists' => 'Predis_Commands_HashExists',
  322. 'hlen' => 'Predis_Commands_HashLength',
  323. 'hashLength' => 'Predis_Commands_HashLength',
  324. 'hkeys' => 'Predis_Commands_HashKeys',
  325. 'hashKeys' => 'Predis_Commands_HashKeys',
  326. 'hvals' => 'Predis_Commands_HashValues',
  327. 'hashValues' => 'Predis_Commands_HashValues',
  328. 'hgetall' => 'Predis_Commands_HashGetAll',
  329. 'hashGetAll' => 'Predis_Commands_HashGetAll',
  330. /* publish - subscribe */
  331. 'subscribe' => 'Predis_Commands_Subscribe',
  332. 'unsubscribe' => 'Predis_Commands_Unsubscribe',
  333. 'psubscribe' => 'Predis_Commands_SubscribeByPattern',
  334. 'punsubscribe' => 'Predis_Commands_UnsubscribeByPattern',
  335. 'publish' => 'Predis_Commands_Publish',
  336. /* remote server control commands */
  337. 'config' => 'Predis_Commands_Config',
  338. 'configuration' => 'Predis_Commands_Config',
  339. ));
  340. }
  341. }
  342. /* ------------------------------------------------------------------------- */
  343. /* miscellaneous commands */
  344. class Predis_Compatibility_v1_0_Commands_Ping extends Predis_InlineCommand {
  345. public function canBeHashed() { return false; }
  346. public function getCommandId() { return 'PING'; }
  347. public function parseResponse($data) {
  348. return $data === 'PONG' ? true : false;
  349. }
  350. }
  351. class Predis_Compatibility_v1_0_Commands_DoEcho extends Predis_BulkCommand {
  352. public function canBeHashed() { return false; }
  353. public function getCommandId() { return 'ECHO'; }
  354. }
  355. class Predis_Compatibility_v1_0_Commands_Auth extends Predis_InlineCommand {
  356. public function canBeHashed() { return false; }
  357. public function getCommandId() { return 'AUTH'; }
  358. }
  359. /* connection handling */
  360. class Predis_Compatibility_v1_0_Commands_Quit extends Predis_InlineCommand {
  361. public function canBeHashed() { return false; }
  362. public function getCommandId() { return 'QUIT'; }
  363. public function closesConnection() { return true; }
  364. }
  365. /* commands operating on string values */
  366. class Predis_Compatibility_v1_0_Commands_Set extends Predis_BulkCommand {
  367. public function getCommandId() { return 'SET'; }
  368. }
  369. class Predis_Compatibility_v1_0_Commands_SetPreserve extends Predis_BulkCommand {
  370. public function getCommandId() { return 'SETNX'; }
  371. public function parseResponse($data) { return (bool) $data; }
  372. }
  373. class Predis_Compatibility_v1_0_Commands_Get extends Predis_InlineCommand {
  374. public function getCommandId() { return 'GET'; }
  375. }
  376. class Predis_Compatibility_v1_0_Commands_GetMultiple extends Predis_InlineCommand {
  377. public function canBeHashed() { return false; }
  378. public function getCommandId() { return 'MGET'; }
  379. }
  380. class Predis_Compatibility_v1_0_Commands_GetSet extends Predis_BulkCommand {
  381. public function getCommandId() { return 'GETSET'; }
  382. }
  383. class Predis_Compatibility_v1_0_Commands_Increment extends Predis_InlineCommand {
  384. public function getCommandId() { return 'INCR'; }
  385. }
  386. class Predis_Compatibility_v1_0_Commands_IncrementBy extends Predis_InlineCommand {
  387. public function getCommandId() { return 'INCRBY'; }
  388. }
  389. class Predis_Compatibility_v1_0_Commands_Decrement extends Predis_InlineCommand {
  390. public function getCommandId() { return 'DECR'; }
  391. }
  392. class Predis_Compatibility_v1_0_Commands_DecrementBy extends Predis_InlineCommand {
  393. public function getCommandId() { return 'DECRBY'; }
  394. }
  395. class Predis_Compatibility_v1_0_Commands_Exists extends Predis_InlineCommand {
  396. public function getCommandId() { return 'EXISTS'; }
  397. public function parseResponse($data) { return (bool) $data; }
  398. }
  399. class Predis_Compatibility_v1_0_Commands_Delete extends Predis_InlineCommand {
  400. public function getCommandId() { return 'DEL'; }
  401. }
  402. class Predis_Compatibility_v1_0_Commands_Type extends Predis_InlineCommand {
  403. public function getCommandId() { return 'TYPE'; }
  404. }
  405. /* commands operating on the key space */
  406. class Predis_Compatibility_v1_0_Commands_Keys extends Predis_InlineCommand {
  407. public function canBeHashed() { return false; }
  408. public function getCommandId() { return 'KEYS'; }
  409. public function parseResponse($data) {
  410. return strlen($data) > 0 ? explode(' ', $data) : array();
  411. }
  412. }
  413. class Predis_Compatibility_v1_0_Commands_RandomKey extends Predis_InlineCommand {
  414. public function canBeHashed() { return false; }
  415. public function getCommandId() { return 'RANDOMKEY'; }
  416. public function parseResponse($data) { return $data !== '' ? $data : null; }
  417. }
  418. class Predis_Compatibility_v1_0_Commands_Rename extends Predis_InlineCommand {
  419. public function canBeHashed() { return false; }
  420. public function getCommandId() { return 'RENAME'; }
  421. }
  422. class Predis_Compatibility_v1_0_Commands_RenamePreserve extends Predis_InlineCommand {
  423. public function canBeHashed() { return false; }
  424. public function getCommandId() { return 'RENAMENX'; }
  425. public function parseResponse($data) { return (bool) $data; }
  426. }
  427. class Predis_Compatibility_v1_0_Commands_Expire extends Predis_InlineCommand {
  428. public function getCommandId() { return 'EXPIRE'; }
  429. public function parseResponse($data) { return (bool) $data; }
  430. }
  431. class Predis_Compatibility_v1_0_Commands_ExpireAt extends Predis_InlineCommand {
  432. public function getCommandId() { return 'EXPIREAT'; }
  433. public function parseResponse($data) { return (bool) $data; }
  434. }
  435. class Predis_Compatibility_v1_0_Commands_DatabaseSize extends Predis_InlineCommand {
  436. public function canBeHashed() { return false; }
  437. public function getCommandId() { return 'DBSIZE'; }
  438. }
  439. class Predis_Compatibility_v1_0_Commands_TimeToLive extends Predis_InlineCommand {
  440. public function getCommandId() { return 'TTL'; }
  441. }
  442. /* commands operating on lists */
  443. class Predis_Compatibility_v1_0_Commands_ListPushTail extends Predis_BulkCommand {
  444. public function getCommandId() { return 'RPUSH'; }
  445. }
  446. class Predis_Compatibility_v1_0_Commands_ListPushHead extends Predis_BulkCommand {
  447. public function getCommandId() { return 'LPUSH'; }
  448. }
  449. class Predis_Compatibility_v1_0_Commands_ListLength extends Predis_InlineCommand {
  450. public function getCommandId() { return 'LLEN'; }
  451. }
  452. class Predis_Compatibility_v1_0_Commands_ListRange extends Predis_InlineCommand {
  453. public function getCommandId() { return 'LRANGE'; }
  454. }
  455. class Predis_Compatibility_v1_0_Commands_ListTrim extends Predis_InlineCommand {
  456. public function getCommandId() { return 'LTRIM'; }
  457. }
  458. class Predis_Compatibility_v1_0_Commands_ListIndex extends Predis_InlineCommand {
  459. public function getCommandId() { return 'LINDEX'; }
  460. }
  461. class Predis_Compatibility_v1_0_Commands_ListSet extends Predis_BulkCommand {
  462. public function getCommandId() { return 'LSET'; }
  463. }
  464. class Predis_Compatibility_v1_0_Commands_ListRemove extends Predis_BulkCommand {
  465. public function getCommandId() { return 'LREM'; }
  466. }
  467. class Predis_Compatibility_v1_0_Commands_ListPopFirst extends Predis_InlineCommand {
  468. public function getCommandId() { return 'LPOP'; }
  469. }
  470. class Predis_Compatibility_v1_0_Commands_ListPopLast extends Predis_InlineCommand {
  471. public function getCommandId() { return 'RPOP'; }
  472. }
  473. /* commands operating on sets */
  474. class Predis_Compatibility_v1_0_Commands_SetAdd extends Predis_BulkCommand {
  475. public function getCommandId() { return 'SADD'; }
  476. public function parseResponse($data) { return (bool) $data; }
  477. }
  478. class Predis_Compatibility_v1_0_Commands_SetRemove extends Predis_BulkCommand {
  479. public function getCommandId() { return 'SREM'; }
  480. public function parseResponse($data) { return (bool) $data; }
  481. }
  482. class Predis_Compatibility_v1_0_Commands_SetPop extends Predis_InlineCommand {
  483. public function getCommandId() { return 'SPOP'; }
  484. }
  485. class Predis_Compatibility_v1_0_Commands_SetMove extends Predis_BulkCommand {
  486. public function canBeHashed() { return false; }
  487. public function getCommandId() { return 'SMOVE'; }
  488. public function parseResponse($data) { return (bool) $data; }
  489. }
  490. class Predis_Compatibility_v1_0_Commands_SetCardinality extends Predis_InlineCommand {
  491. public function getCommandId() { return 'SCARD'; }
  492. }
  493. class Predis_Compatibility_v1_0_Commands_SetIsMember extends Predis_BulkCommand {
  494. public function getCommandId() { return 'SISMEMBER'; }
  495. public function parseResponse($data) { return (bool) $data; }
  496. }
  497. class Predis_Compatibility_v1_0_Commands_SetIntersection extends Predis_InlineCommand {
  498. public function getCommandId() { return 'SINTER'; }
  499. }
  500. class Predis_Compatibility_v1_0_Commands_SetIntersectionStore extends Predis_InlineCommand {
  501. public function getCommandId() { return 'SINTERSTORE'; }
  502. }
  503. class Predis_Compatibility_v1_0_Commands_SetUnion extends Predis_InlineCommand {
  504. public function getCommandId() { return 'SUNION'; }
  505. }
  506. class Predis_Compatibility_v1_0_Commands_SetUnionStore extends Predis_InlineCommand {
  507. public function getCommandId() { return 'SUNIONSTORE'; }
  508. }
  509. class Predis_Compatibility_v1_0_Commands_SetDifference extends Predis_InlineCommand {
  510. public function getCommandId() { return 'SDIFF'; }
  511. }
  512. class Predis_Compatibility_v1_0_Commands_SetDifferenceStore extends Predis_InlineCommand {
  513. public function getCommandId() { return 'SDIFFSTORE'; }
  514. }
  515. class Predis_Compatibility_v1_0_Commands_SetMembers extends Predis_InlineCommand {
  516. public function getCommandId() { return 'SMEMBERS'; }
  517. }
  518. class Predis_Compatibility_v1_0_Commands_SetRandomMember extends Predis_InlineCommand {
  519. public function getCommandId() { return 'SRANDMEMBER'; }
  520. }
  521. /* multiple databases handling commands */
  522. class Predis_Compatibility_v1_0_Commands_SelectDatabase extends Predis_InlineCommand {
  523. public function canBeHashed() { return false; }
  524. public function getCommandId() { return 'SELECT'; }
  525. }
  526. class Predis_Compatibility_v1_0_Commands_MoveKey extends Predis_InlineCommand {
  527. public function canBeHashed() { return false; }
  528. public function getCommandId() { return 'MOVE'; }
  529. public function parseResponse($data) { return (bool) $data; }
  530. }
  531. class Predis_Compatibility_v1_0_Commands_FlushDatabase extends Predis_InlineCommand {
  532. public function canBeHashed() { return false; }
  533. public function getCommandId() { return 'FLUSHDB'; }
  534. }
  535. class Predis_Compatibility_v1_0_Commands_FlushAll extends Predis_InlineCommand {
  536. public function canBeHashed() { return false; }
  537. public function getCommandId() { return 'FLUSHALL'; }
  538. }
  539. /* sorting */
  540. class Predis_Compatibility_v1_0_Commands_Sort extends Predis_InlineCommand {
  541. public function getCommandId() { return 'SORT'; }
  542. public function filterArguments(Array $arguments) {
  543. if (count($arguments) === 1) {
  544. return $arguments;
  545. }
  546. // TODO: add more parameters checks
  547. $query = array($arguments[0]);
  548. $sortParams = $arguments[1];
  549. if (isset($sortParams['by'])) {
  550. $query[] = 'BY';
  551. $query[] = $sortParams['by'];
  552. }
  553. if (isset($sortParams['get'])) {
  554. $getargs = $sortParams['get'];
  555. if (is_array($getargs)) {
  556. foreach ($getargs as $getarg) {
  557. $query[] = 'GET';
  558. $query[] = $getarg;
  559. }
  560. }
  561. else {
  562. $query[] = 'GET';
  563. $query[] = $getargs;
  564. }
  565. }
  566. if (isset($sortParams['limit']) && is_array($sortParams['limit'])) {
  567. $query[] = 'LIMIT';
  568. $query[] = $sortParams['limit'][0];
  569. $query[] = $sortParams['limit'][1];
  570. }
  571. if (isset($sortParams['sort'])) {
  572. $query[] = strtoupper($sortParams['sort']);
  573. }
  574. if (isset($sortParams['alpha']) && $sortParams['alpha'] == true) {
  575. $query[] = 'ALPHA';
  576. }
  577. if (isset($sortParams['store']) && $sortParams['store'] == true) {
  578. $query[] = 'STORE';
  579. $query[] = $sortParams['store'];
  580. }
  581. return $query;
  582. }
  583. }
  584. /* persistence control commands */
  585. class Predis_Compatibility_v1_0_Commands_Save extends Predis_InlineCommand {
  586. public function canBeHashed() { return false; }
  587. public function getCommandId() { return 'SAVE'; }
  588. }
  589. class Predis_Compatibility_v1_0_Commands_BackgroundSave extends Predis_InlineCommand {
  590. public function canBeHashed() { return false; }
  591. public function getCommandId() { return 'BGSAVE'; }
  592. public function parseResponse($data) {
  593. if ($data == 'Background saving started') {
  594. return true;
  595. }
  596. return $data;
  597. }
  598. }
  599. class Predis_Compatibility_v1_0_Commands_LastSave extends Predis_InlineCommand {
  600. public function canBeHashed() { return false; }
  601. public function getCommandId() { return 'LASTSAVE'; }
  602. }
  603. class Predis_Compatibility_v1_0_Commands_Shutdown extends Predis_InlineCommand {
  604. public function canBeHashed() { return false; }
  605. public function getCommandId() { return 'SHUTDOWN'; }
  606. public function closesConnection() { return true; }
  607. }
  608. /* remote server control commands */
  609. class Predis_Compatibility_v1_0_Commands_Info extends Predis_InlineCommand {
  610. public function canBeHashed() { return false; }
  611. public function getCommandId() { return 'INFO'; }
  612. public function parseResponse($data) {
  613. $info = array();
  614. $infoLines = explode("\r\n", $data, -1);
  615. foreach ($infoLines as $row) {
  616. list($k, $v) = explode(':', $row);
  617. if (!preg_match('/^db\d+$/', $k)) {
  618. $info[$k] = $v;
  619. }
  620. else {
  621. $db = array();
  622. foreach (explode(',', $v) as $dbvar) {
  623. list($dbvk, $dbvv) = explode('=', $dbvar);
  624. $db[trim($dbvk)] = $dbvv;
  625. }
  626. $info[$k] = $db;
  627. }
  628. }
  629. return $info;
  630. }
  631. }
  632. class Predis_Compatibility_v1_0_Commands_SlaveOf extends Predis_InlineCommand {
  633. public function canBeHashed() { return false; }
  634. public function getCommandId() { return 'SLAVEOF'; }
  635. public function filterArguments(Array $arguments) {
  636. if (count($arguments) === 0 || $arguments[0] === 'NO ONE') {
  637. return array('NO', 'ONE');
  638. }
  639. return $arguments;
  640. }
  641. }
  642. ?>