Predis_Compatibility.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <?php
  2. Predis_RedisServerProfile::registerProfile('Predis_RedisServer_v1_0', '1.0');
  3. class Predis_RedisServer_v1_0 extends Predis_RedisServerProfile {
  4. public function getVersion() { return '1.0'; }
  5. public function getSupportedCommands() {
  6. return array(
  7. /* miscellaneous commands */
  8. 'ping' => 'Predis_Compatibility_v1_0_Commands_Ping',
  9. 'echo' => 'Predis_Compatibility_v1_0_Commands_DoEcho',
  10. 'auth' => 'Predis_Compatibility_v1_0_Commands_Auth',
  11. /* connection handling */
  12. 'quit' => 'Predis_Compatibility_v1_0_Commands_Quit',
  13. /* commands operating on string values */
  14. 'set' => 'Predis_Compatibility_v1_0_Commands_Set',
  15. 'setnx' => 'Predis_Compatibility_v1_0_Commands_SetPreserve',
  16. 'setPreserve' => 'Predis_Compatibility_v1_0_Commands_SetPreserve',
  17. 'get' => 'Predis_Compatibility_v1_0_Commands_Get',
  18. 'mget' => 'Predis_Compatibility_v1_0_Commands_GetMultiple',
  19. 'getMultiple' => 'Predis_Compatibility_v1_0_Commands_GetMultiple',
  20. 'getset' => 'Predis_Compatibility_v1_0_Commands_GetSet',
  21. 'getSet' => 'Predis_Compatibility_v1_0_Commands_GetSet',
  22. 'incr' => 'Predis_Compatibility_v1_0_Commands_Increment',
  23. 'increment' => 'Predis_Compatibility_v1_0_Commands_Increment',
  24. 'incrby' => 'Predis_Compatibility_v1_0_Commands_IncrementBy',
  25. 'incrementBy' => 'Predis_Compatibility_v1_0_Commands_IncrementBy',
  26. 'decr' => 'Predis_Compatibility_v1_0_Commands_Decrement',
  27. 'decrement' => 'Predis_Compatibility_v1_0_Commands_Decrement',
  28. 'decrby' => 'Predis_Compatibility_v1_0_Commands_DecrementBy',
  29. 'decrementBy' => 'Predis_Compatibility_v1_0_Commands_DecrementBy',
  30. 'exists' => 'Predis_Compatibility_v1_0_Commands_Exists',
  31. 'del' => 'Predis_Compatibility_v1_0_Commands_Delete',
  32. 'delete' => 'Predis_Compatibility_v1_0_Commands_Delete',
  33. 'type' => 'Predis_Compatibility_v1_0_Commands_Type',
  34. /* commands operating on the key space */
  35. 'keys' => 'Predis_Compatibility_v1_0_Commands_Keys',
  36. 'randomkey' => 'Predis_Compatibility_v1_0_Commands_RandomKey',
  37. 'randomKey' => 'Predis_Compatibility_v1_0_Commands_RandomKey',
  38. 'rename' => 'Predis_Compatibility_v1_0_Commands_Rename',
  39. 'renamenx' => 'Predis_Compatibility_v1_0_Commands_RenamePreserve',
  40. 'renamePreserve' => 'Predis_Compatibility_v1_0_Commands_RenamePreserve',
  41. 'expire' => 'Predis_Compatibility_v1_0_Commands_Expire',
  42. 'expireat' => 'Predis_Compatibility_v1_0_Commands_ExpireAt',
  43. 'expireAt' => 'Predis_Compatibility_v1_0_Commands_ExpireAt',
  44. 'dbsize' => 'Predis_Compatibility_v1_0_Commands_DatabaseSize',
  45. 'databaseSize' => 'Predis_Compatibility_v1_0_Commands_DatabaseSize',
  46. 'ttl' => 'Predis_Compatibility_v1_0_Commands_TimeToLive',
  47. 'timeToLive' => 'Predis_Compatibility_v1_0_Commands_TimeToLive',
  48. /* commands operating on lists */
  49. 'rpush' => 'Predis_Compatibility_v1_0_Commands_ListPushTail',
  50. 'pushTail' => 'Predis_Compatibility_v1_0_Commands_ListPushTail',
  51. 'lpush' => 'Predis_Compatibility_v1_0_Commands_ListPushHead',
  52. 'pushHead' => 'Predis_Compatibility_v1_0_Commands_ListPushHead',
  53. 'llen' => 'Predis_Compatibility_v1_0_Commands_ListLength',
  54. 'listLength' => 'Predis_Compatibility_v1_0_Commands_ListLength',
  55. 'lrange' => 'Predis_Compatibility_v1_0_Commands_ListRange',
  56. 'listRange' => 'Predis_Compatibility_v1_0_Commands_ListRange',
  57. 'ltrim' => 'Predis_Compatibility_v1_0_Commands_ListTrim',
  58. 'listTrim' => 'Predis_Compatibility_v1_0_Commands_ListTrim',
  59. 'lindex' => 'Predis_Compatibility_v1_0_Commands_ListIndex',
  60. 'listIndex' => 'Predis_Compatibility_v1_0_Commands_ListIndex',
  61. 'lset' => 'Predis_Compatibility_v1_0_Commands_ListSet',
  62. 'listSet' => 'Predis_Compatibility_v1_0_Commands_ListSet',
  63. 'lrem' => 'Predis_Compatibility_v1_0_Commands_ListRemove',
  64. 'listRemove' => 'Predis_Compatibility_v1_0_Commands_ListRemove',
  65. 'lpop' => 'Predis_Compatibility_v1_0_Commands_ListPopFirst',
  66. 'popFirst' => 'Predis_Compatibility_v1_0_Commands_ListPopFirst',
  67. 'rpop' => 'Predis_Compatibility_v1_0_Commands_ListPopLast',
  68. 'popLast' => 'Predis_Compatibility_v1_0_Commands_ListPopLast',
  69. /* commands operating on sets */
  70. 'sadd' => 'Predis_Compatibility_v1_0_Commands_SetAdd',
  71. 'setAdd' => 'Predis_Compatibility_v1_0_Commands_SetAdd',
  72. 'srem' => 'Predis_Compatibility_v1_0_Commands_SetRemove',
  73. 'setRemove' => 'Predis_Compatibility_v1_0_Commands_SetRemove',
  74. 'spop' => 'Predis_Compatibility_v1_0_Commands_SetPop',
  75. 'setPop' => 'Predis_Compatibility_v1_0_Commands_SetPop',
  76. 'smove' => 'Predis_Compatibility_v1_0_Commands_SetMove',
  77. 'setMove' => 'Predis_Compatibility_v1_0_Commands_SetMove',
  78. 'scard' => 'Predis_Compatibility_v1_0_Commands_SetCardinality',
  79. 'setCardinality' => 'Predis_Compatibility_v1_0_Commands_SetCardinality',
  80. 'sismember' => 'Predis_Compatibility_v1_0_Commands_SetIsMember',
  81. 'setIsMember' => 'Predis_Compatibility_v1_0_Commands_SetIsMember',
  82. 'sinter' => 'Predis_Compatibility_v1_0_Commands_SetIntersection',
  83. 'setIntersection' => 'Predis_Compatibility_v1_0_Commands_SetIntersection',
  84. 'sinterstore' => 'Predis_Compatibility_v1_0_Commands_SetIntersectionStore',
  85. 'setIntersectionStore' => 'Predis_Compatibility_v1_0_Commands_SetIntersectionStore',
  86. 'sunion' => 'Predis_Compatibility_v1_0_Commands_SetUnion',
  87. 'setUnion' => 'Predis_Compatibility_v1_0_Commands_SetUnion',
  88. 'sunionstore' => 'Predis_Compatibility_v1_0_Commands_SetUnionStore',
  89. 'setUnionStore' => 'Predis_Compatibility_v1_0_Commands_SetUnionStore',
  90. 'sdiff' => 'Predis_Compatibility_v1_0_Commands_SetDifference',
  91. 'setDifference' => 'Predis_Compatibility_v1_0_Commands_SetDifference',
  92. 'sdiffstore' => 'Predis_Compatibility_v1_0_Commands_SetDifferenceStore',
  93. 'setDifferenceStore' => 'Predis_Compatibility_v1_0_Commands_SetDifferenceStore',
  94. 'smembers' => 'Predis_Compatibility_v1_0_Commands_SetMembers',
  95. 'setMembers' => 'Predis_Compatibility_v1_0_Commands_SetMembers',
  96. 'srandmember' => 'Predis_Compatibility_v1_0_Commands_SetRandomMember',
  97. 'setRandomMember' => 'Predis_Compatibility_v1_0_Commands_SetRandomMember',
  98. /* multiple databases handling commands */
  99. 'select' => 'Predis_Compatibility_v1_0_Commands_SelectDatabase',
  100. 'selectDatabase' => 'Predis_Compatibility_v1_0_Commands_SelectDatabase',
  101. 'move' => 'Predis_Compatibility_v1_0_Commands_MoveKey',
  102. 'moveKey' => 'Predis_Compatibility_v1_0_Commands_MoveKey',
  103. 'flushdb' => 'Predis_Compatibility_v1_0_Commands_FlushDatabase',
  104. 'flushDatabase' => 'Predis_Compatibility_v1_0_Commands_FlushDatabase',
  105. 'flushall' => 'Predis_Compatibility_v1_0_Commands_FlushAll',
  106. 'flushDatabases' => 'Predis_Compatibility_v1_0_Commands_FlushAll',
  107. /* sorting */
  108. 'sort' => 'Predis_Compatibility_v1_0_Commands_Sort',
  109. /* remote server control commands */
  110. 'info' => 'Predis_Compatibility_v1_0_Commands_Info',
  111. 'slaveof' => 'Predis_Compatibility_v1_0_Commands_SlaveOf',
  112. 'slaveOf' => 'Predis_Compatibility_v1_0_Commands_SlaveOf',
  113. /* persistence control commands */
  114. 'save' => 'Predis_Compatibility_v1_0_Commands_Save',
  115. 'bgsave' => 'Predis_Compatibility_v1_0_Commands_BackgroundSave',
  116. 'backgroundSave' => 'Predis_Compatibility_v1_0_Commands_BackgroundSave',
  117. 'lastsave' => 'Predis_Compatibility_v1_0_Commands_LastSave',
  118. 'lastSave' => 'Predis_Compatibility_v1_0_Commands_LastSave',
  119. 'shutdown' => 'Predis_Compatibility_v1_0_Commands_Shutdown',
  120. );
  121. }
  122. }
  123. /* ------------------------------------------------------------------------- */
  124. /* miscellaneous commands */
  125. class Predis_Compatibility_v1_0_Commands_Ping extends Predis_InlineCommand {
  126. public function canBeHashed() { return false; }
  127. public function getCommandId() { return 'PING'; }
  128. public function parseResponse($data) {
  129. return $data === 'PONG' ? true : false;
  130. }
  131. }
  132. class Predis_Compatibility_v1_0_Commands_DoEcho extends Predis_BulkCommand {
  133. public function canBeHashed() { return false; }
  134. public function getCommandId() { return 'ECHO'; }
  135. }
  136. class Predis_Compatibility_v1_0_Commands_Auth extends Predis_InlineCommand {
  137. public function canBeHashed() { return false; }
  138. public function getCommandId() { return 'AUTH'; }
  139. }
  140. /* connection handling */
  141. class Predis_Compatibility_v1_0_Commands_Quit extends Predis_InlineCommand {
  142. public function canBeHashed() { return false; }
  143. public function getCommandId() { return 'QUIT'; }
  144. public function closesConnection() { return true; }
  145. }
  146. /* commands operating on string values */
  147. class Predis_Compatibility_v1_0_Commands_Set extends Predis_BulkCommand {
  148. public function getCommandId() { return 'SET'; }
  149. }
  150. class Predis_Compatibility_v1_0_Commands_SetPreserve extends Predis_BulkCommand {
  151. public function getCommandId() { return 'SETNX'; }
  152. public function parseResponse($data) { return (bool) $data; }
  153. }
  154. class Predis_Compatibility_v1_0_Commands_Get extends Predis_InlineCommand {
  155. public function getCommandId() { return 'GET'; }
  156. }
  157. class Predis_Compatibility_v1_0_Commands_GetMultiple extends Predis_InlineCommand {
  158. public function canBeHashed() { return false; }
  159. public function getCommandId() { return 'MGET'; }
  160. }
  161. class Predis_Compatibility_v1_0_Commands_GetSet extends Predis_BulkCommand {
  162. public function getCommandId() { return 'GETSET'; }
  163. }
  164. class Predis_Compatibility_v1_0_Commands_Increment extends Predis_InlineCommand {
  165. public function getCommandId() { return 'INCR'; }
  166. }
  167. class Predis_Compatibility_v1_0_Commands_IncrementBy extends Predis_InlineCommand {
  168. public function getCommandId() { return 'INCRBY'; }
  169. }
  170. class Predis_Compatibility_v1_0_Commands_Decrement extends Predis_InlineCommand {
  171. public function getCommandId() { return 'DECR'; }
  172. }
  173. class Predis_Compatibility_v1_0_Commands_DecrementBy extends Predis_InlineCommand {
  174. public function getCommandId() { return 'DECRBY'; }
  175. }
  176. class Predis_Compatibility_v1_0_Commands_Exists extends Predis_InlineCommand {
  177. public function getCommandId() { return 'EXISTS'; }
  178. public function parseResponse($data) { return (bool) $data; }
  179. }
  180. class Predis_Compatibility_v1_0_Commands_Delete extends Predis_InlineCommand {
  181. public function getCommandId() { return 'DEL'; }
  182. }
  183. class Predis_Compatibility_v1_0_Commands_Type extends Predis_InlineCommand {
  184. public function getCommandId() { return 'TYPE'; }
  185. }
  186. /* commands operating on the key space */
  187. class Predis_Compatibility_v1_0_Commands_Keys extends Predis_InlineCommand {
  188. public function canBeHashed() { return false; }
  189. public function getCommandId() { return 'KEYS'; }
  190. public function parseResponse($data) {
  191. return strlen($data) > 0 ? explode(' ', $data) : array();
  192. }
  193. }
  194. class Predis_Compatibility_v1_0_Commands_RandomKey extends Predis_InlineCommand {
  195. public function canBeHashed() { return false; }
  196. public function getCommandId() { return 'RANDOMKEY'; }
  197. public function parseResponse($data) { return $data !== '' ? $data : null; }
  198. }
  199. class Predis_Compatibility_v1_0_Commands_Rename extends Predis_InlineCommand {
  200. public function canBeHashed() { return false; }
  201. public function getCommandId() { return 'RENAME'; }
  202. }
  203. class Predis_Compatibility_v1_0_Commands_RenamePreserve extends Predis_InlineCommand {
  204. public function canBeHashed() { return false; }
  205. public function getCommandId() { return 'RENAMENX'; }
  206. public function parseResponse($data) { return (bool) $data; }
  207. }
  208. class Predis_Compatibility_v1_0_Commands_Expire extends Predis_InlineCommand {
  209. public function getCommandId() { return 'EXPIRE'; }
  210. public function parseResponse($data) { return (bool) $data; }
  211. }
  212. class Predis_Compatibility_v1_0_Commands_ExpireAt extends Predis_InlineCommand {
  213. public function getCommandId() { return 'EXPIREAT'; }
  214. public function parseResponse($data) { return (bool) $data; }
  215. }
  216. class Predis_Compatibility_v1_0_Commands_DatabaseSize extends Predis_InlineCommand {
  217. public function canBeHashed() { return false; }
  218. public function getCommandId() { return 'DBSIZE'; }
  219. }
  220. class Predis_Compatibility_v1_0_Commands_TimeToLive extends Predis_InlineCommand {
  221. public function getCommandId() { return 'TTL'; }
  222. }
  223. /* commands operating on lists */
  224. class Predis_Compatibility_v1_0_Commands_ListPushTail extends Predis_BulkCommand {
  225. public function getCommandId() { return 'RPUSH'; }
  226. }
  227. class Predis_Compatibility_v1_0_Commands_ListPushHead extends Predis_BulkCommand {
  228. public function getCommandId() { return 'LPUSH'; }
  229. }
  230. class Predis_Compatibility_v1_0_Commands_ListLength extends Predis_InlineCommand {
  231. public function getCommandId() { return 'LLEN'; }
  232. }
  233. class Predis_Compatibility_v1_0_Commands_ListRange extends Predis_InlineCommand {
  234. public function getCommandId() { return 'LRANGE'; }
  235. }
  236. class Predis_Compatibility_v1_0_Commands_ListTrim extends Predis_InlineCommand {
  237. public function getCommandId() { return 'LTRIM'; }
  238. }
  239. class Predis_Compatibility_v1_0_Commands_ListIndex extends Predis_InlineCommand {
  240. public function getCommandId() { return 'LINDEX'; }
  241. }
  242. class Predis_Compatibility_v1_0_Commands_ListSet extends Predis_BulkCommand {
  243. public function getCommandId() { return 'LSET'; }
  244. }
  245. class Predis_Compatibility_v1_0_Commands_ListRemove extends Predis_BulkCommand {
  246. public function getCommandId() { return 'LREM'; }
  247. }
  248. class Predis_Compatibility_v1_0_Commands_ListPopFirst extends Predis_InlineCommand {
  249. public function getCommandId() { return 'LPOP'; }
  250. }
  251. class Predis_Compatibility_v1_0_Commands_ListPopLast extends Predis_InlineCommand {
  252. public function getCommandId() { return 'RPOP'; }
  253. }
  254. /* commands operating on sets */
  255. class Predis_Compatibility_v1_0_Commands_SetAdd extends Predis_BulkCommand {
  256. public function getCommandId() { return 'SADD'; }
  257. public function parseResponse($data) { return (bool) $data; }
  258. }
  259. class Predis_Compatibility_v1_0_Commands_SetRemove extends Predis_BulkCommand {
  260. public function getCommandId() { return 'SREM'; }
  261. public function parseResponse($data) { return (bool) $data; }
  262. }
  263. class Predis_Compatibility_v1_0_Commands_SetPop extends Predis_InlineCommand {
  264. public function getCommandId() { return 'SPOP'; }
  265. }
  266. class Predis_Compatibility_v1_0_Commands_SetMove extends Predis_BulkCommand {
  267. public function canBeHashed() { return false; }
  268. public function getCommandId() { return 'SMOVE'; }
  269. public function parseResponse($data) { return (bool) $data; }
  270. }
  271. class Predis_Compatibility_v1_0_Commands_SetCardinality extends Predis_InlineCommand {
  272. public function getCommandId() { return 'SCARD'; }
  273. }
  274. class Predis_Compatibility_v1_0_Commands_SetIsMember extends Predis_BulkCommand {
  275. public function getCommandId() { return 'SISMEMBER'; }
  276. public function parseResponse($data) { return (bool) $data; }
  277. }
  278. class Predis_Compatibility_v1_0_Commands_SetIntersection extends Predis_InlineCommand {
  279. public function getCommandId() { return 'SINTER'; }
  280. }
  281. class Predis_Compatibility_v1_0_Commands_SetIntersectionStore extends Predis_InlineCommand {
  282. public function getCommandId() { return 'SINTERSTORE'; }
  283. }
  284. class Predis_Compatibility_v1_0_Commands_SetUnion extends Predis_InlineCommand {
  285. public function getCommandId() { return 'SUNION'; }
  286. }
  287. class Predis_Compatibility_v1_0_Commands_SetUnionStore extends Predis_InlineCommand {
  288. public function getCommandId() { return 'SUNIONSTORE'; }
  289. }
  290. class Predis_Compatibility_v1_0_Commands_SetDifference extends Predis_InlineCommand {
  291. public function getCommandId() { return 'SDIFF'; }
  292. }
  293. class Predis_Compatibility_v1_0_Commands_SetDifferenceStore extends Predis_InlineCommand {
  294. public function getCommandId() { return 'SDIFFSTORE'; }
  295. }
  296. class Predis_Compatibility_v1_0_Commands_SetMembers extends Predis_InlineCommand {
  297. public function getCommandId() { return 'SMEMBERS'; }
  298. }
  299. class Predis_Compatibility_v1_0_Commands_SetRandomMember extends Predis_InlineCommand {
  300. public function getCommandId() { return 'SRANDMEMBER'; }
  301. }
  302. /* multiple databases handling commands */
  303. class Predis_Compatibility_v1_0_Commands_SelectDatabase extends Predis_InlineCommand {
  304. public function canBeHashed() { return false; }
  305. public function getCommandId() { return 'SELECT'; }
  306. }
  307. class Predis_Compatibility_v1_0_Commands_MoveKey extends Predis_InlineCommand {
  308. public function canBeHashed() { return false; }
  309. public function getCommandId() { return 'MOVE'; }
  310. public function parseResponse($data) { return (bool) $data; }
  311. }
  312. class Predis_Compatibility_v1_0_Commands_FlushDatabase extends Predis_InlineCommand {
  313. public function canBeHashed() { return false; }
  314. public function getCommandId() { return 'FLUSHDB'; }
  315. }
  316. class Predis_Compatibility_v1_0_Commands_FlushAll extends Predis_InlineCommand {
  317. public function canBeHashed() { return false; }
  318. public function getCommandId() { return 'FLUSHALL'; }
  319. }
  320. /* sorting */
  321. class Predis_Compatibility_v1_0_Commands_Sort extends Predis_InlineCommand {
  322. public function getCommandId() { return 'SORT'; }
  323. public function filterArguments(Array $arguments) {
  324. if (count($arguments) === 1) {
  325. return $arguments;
  326. }
  327. // TODO: add more parameters checks
  328. $query = array($arguments[0]);
  329. $sortParams = $arguments[1];
  330. if (isset($sortParams['by'])) {
  331. $query[] = 'BY';
  332. $query[] = $sortParams['by'];
  333. }
  334. if (isset($sortParams['get'])) {
  335. $getargs = $sortParams['get'];
  336. if (is_array($getargs)) {
  337. foreach ($getargs as $getarg) {
  338. $query[] = 'GET';
  339. $query[] = $getarg;
  340. }
  341. }
  342. else {
  343. $query[] = 'GET';
  344. $query[] = $getargs;
  345. }
  346. }
  347. if (isset($sortParams['limit']) && is_array($sortParams['limit'])) {
  348. $query[] = 'LIMIT';
  349. $query[] = $sortParams['limit'][0];
  350. $query[] = $sortParams['limit'][1];
  351. }
  352. if (isset($sortParams['sort'])) {
  353. $query[] = strtoupper($sortParams['sort']);
  354. }
  355. if (isset($sortParams['alpha']) && $sortParams['alpha'] == true) {
  356. $query[] = 'ALPHA';
  357. }
  358. if (isset($sortParams['store']) && $sortParams['store'] == true) {
  359. $query[] = 'STORE';
  360. $query[] = $sortParams['store'];
  361. }
  362. return $query;
  363. }
  364. }
  365. /* persistence control commands */
  366. class Predis_Compatibility_v1_0_Commands_Save extends Predis_InlineCommand {
  367. public function canBeHashed() { return false; }
  368. public function getCommandId() { return 'SAVE'; }
  369. }
  370. class Predis_Compatibility_v1_0_Commands_BackgroundSave extends Predis_InlineCommand {
  371. public function canBeHashed() { return false; }
  372. public function getCommandId() { return 'BGSAVE'; }
  373. public function parseResponse($data) {
  374. if ($data == 'Background saving started') {
  375. return true;
  376. }
  377. return $data;
  378. }
  379. }
  380. class Predis_Compatibility_v1_0_Commands_LastSave extends Predis_InlineCommand {
  381. public function canBeHashed() { return false; }
  382. public function getCommandId() { return 'LASTSAVE'; }
  383. }
  384. class Predis_Compatibility_v1_0_Commands_Shutdown extends Predis_InlineCommand {
  385. public function canBeHashed() { return false; }
  386. public function getCommandId() { return 'SHUTDOWN'; }
  387. public function closesConnection() { return true; }
  388. }
  389. /* remote server control commands */
  390. class Predis_Compatibility_v1_0_Commands_Info extends Predis_InlineCommand {
  391. public function canBeHashed() { return false; }
  392. public function getCommandId() { return 'INFO'; }
  393. public function parseResponse($data) {
  394. $info = array();
  395. $infoLines = explode("\r\n", $data, -1);
  396. foreach ($infoLines as $row) {
  397. list($k, $v) = explode(':', $row);
  398. if (!preg_match('/^db\d+$/', $k)) {
  399. $info[$k] = $v;
  400. }
  401. else {
  402. $db = array();
  403. foreach (explode(',', $v) as $dbvar) {
  404. list($dbvk, $dbvv) = explode('=', $dbvar);
  405. $db[trim($dbvk)] = $dbvv;
  406. }
  407. $info[$k] = $db;
  408. }
  409. }
  410. return $info;
  411. }
  412. }
  413. class Predis_Compatibility_v1_0_Commands_SlaveOf extends Predis_InlineCommand {
  414. public function canBeHashed() { return false; }
  415. public function getCommandId() { return 'SLAVEOF'; }
  416. public function filterArguments(Array $arguments) {
  417. if (count($arguments) === 0 || $arguments[0] === 'NO ONE') {
  418. return array('NO', 'ONE');
  419. }
  420. return $arguments;
  421. }
  422. }
  423. ?>