PageRenderTime 206ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

/modules/rediska/vendor/rediska/Rediska/Pipeline.php

https://bitbucket.org/sudak/rating
PHP | 938 lines | 173 code | 105 blank | 660 comment | 8 complexity | 9be162063a1f0769859f5e2bdd5b88fa MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Rediska pipeline
  4. *
  5. * @author Ivan Shumkov
  6. * @package Rediska
  7. * @version @package_version@
  8. * @link http://rediska.geometria-lab.net
  9. * @license http://www.opensource.org/licenses/bsd-license.php
  10. */
  11. class Rediska_Pipeline
  12. {
  13. /**
  14. * Rediska instance
  15. *
  16. * @var Rediska
  17. */
  18. protected $_rediska;
  19. /**
  20. * Rediska specified connection instance
  21. *
  22. * @var Rediska_Connection_Specified
  23. */
  24. protected $_specifiedConnection;
  25. /**
  26. * Default pipeline connection
  27. *
  28. * @var Rediska_Connection
  29. */
  30. protected $_defaultConnection;
  31. /**
  32. * One time connection
  33. *
  34. * @var Rediska_Connection
  35. */
  36. protected $_oneTimeConnection;
  37. /**
  38. * Commands buffer
  39. *
  40. * @var array
  41. */
  42. protected $_commands = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param Rediska $rediska Rediska instance
  47. * @param Rediska_Connection_Specified $specifiedConnection Specified connection
  48. */
  49. public function __construct(Rediska $rediska, Rediska_Connection_Specified $specifiedConnection)
  50. {
  51. $this->_rediska = $rediska;
  52. $this->_specifiedConnection = $specifiedConnection;
  53. $this->_defaultConnection = $specifiedConnection->getConnection();
  54. }
  55. /**
  56. * Execute pipelined commands
  57. *
  58. * @return array
  59. */
  60. public function execute()
  61. {
  62. $results = array();
  63. if (!empty($this->_commands)) {
  64. $this->_rediska->getProfiler()->start($this);
  65. foreach($this->_commands as $command) {
  66. $command->write();
  67. }
  68. foreach($this->_commands as $command) {
  69. $results[] = $command->read();
  70. }
  71. $this->_rediska->getProfiler()->stop();
  72. }
  73. return $results;
  74. }
  75. /**
  76. * Magic method for execute
  77. *
  78. * @return array
  79. */
  80. public function __invoke()
  81. {
  82. return $this->execute();
  83. }
  84. /**
  85. * Magic method for add command to pipeline
  86. *
  87. * @param string $name Command name
  88. * @param array $args Arguments
  89. * @return Rediska_Pipeline
  90. */
  91. public function __call($name, $args)
  92. {
  93. if (strtolower($name) == 'on' && isset($args[0])) {
  94. $this->_rediska->on($args[0]);
  95. $this->_oneTimeConnection = $this->_specifiedConnection->getConnection();
  96. return $this;
  97. }
  98. // TODO: Implement transaction and config
  99. if (in_array(strtolower($name), array('transaction', 'config'))) {
  100. throw new Rediska_Exception("$name in pipeline not implemented yet.");
  101. }
  102. if (in_array(strtolower($name), array('monitor', 'subscribe'))) {
  103. throw new Rediska_Transaction_Exception("You can't use '$name' in pipeline");
  104. }
  105. return $this->_addCommand($name, $args);
  106. }
  107. /**
  108. * Add command to pipeline
  109. *
  110. * @param string $name Command name
  111. * @param array $args Arguments
  112. * @return Rediska_Pipeline
  113. */
  114. protected function _addCommand($name, $args = array())
  115. {
  116. if ($this->_oneTimeConnection) {
  117. $connection = $this->_oneTimeConnection;
  118. $this->_oneTimeConnection = null;
  119. } else {
  120. $connection = $this->_defaultConnection;
  121. }
  122. if ($connection !== null) {
  123. $this->_specifiedConnection->setConnection($connection);
  124. } else {
  125. $this->_specifiedConnection->resetConnection();
  126. }
  127. $command = Rediska_Commands::get($this->_rediska, $name, $args);
  128. $command->initialize();
  129. if (!$command->isAtomic()) {
  130. throw new Rediska_Exception("Command '$name' doesn't work properly (not atomic) in pipeline on multiple servers");
  131. }
  132. $this->_commands[] = $command;
  133. $this->_specifiedConnection->resetConnection();
  134. return $this;
  135. }
  136. /**
  137. * Magic to string
  138. *
  139. * @return string
  140. */
  141. public function __toString()
  142. {
  143. if (empty($this->_commands)) {
  144. $string = 'Empty pipeline';
  145. } else {
  146. $string = 'Pipeline: ' . implode(', ', $this->_commands);
  147. }
  148. return $string;
  149. }
  150. /**
  151. * Generated command methods by 'scripts/add_command_methods.php'
  152. */
  153. /**
  154. * Ask the server to silently close the connection.
  155. *
  156. * @return Rediska_Pipeline
  157. */
  158. public function quit() { $args = func_get_args(); return $this->_addCommand('quit', $args); }
  159. /**
  160. * Test if a key exists
  161. *
  162. * @param string $key Key name
  163. * @return Rediska_Pipeline
  164. */
  165. public function exists($key) { $args = func_get_args(); return $this->_addCommand('exists', $args); }
  166. /**
  167. * Delete a key or keys
  168. *
  169. * @param string|array $keyOrKeys Key name or array of key names
  170. * @return Rediska_Pipeline
  171. */
  172. public function delete($keyOrKeys) { $args = func_get_args(); return $this->_addCommand('delete', $args); }
  173. /**
  174. * Get key type
  175. *
  176. * @param string $key Key name
  177. * @return Rediska_Pipeline
  178. */
  179. public function getType($key) { $args = func_get_args(); return $this->_addCommand('getType', $args); }
  180. /**
  181. * Returns all the keys matching the glob-style pattern
  182. * Glob style patterns examples:
  183. * h?llo will match hello hallo hhllo
  184. * h*llo will match hllo heeeello
  185. * h[ae]llo will match hello and hallo, but not hillo
  186. *
  187. * @param string $pattern Pattern
  188. * @return Rediska_Pipeline
  189. */
  190. public function getKeysByPattern($pattern) { $args = func_get_args(); return $this->_addCommand('getKeysByPattern', $args); }
  191. /**
  192. * Return a random key from the key space
  193. *
  194. * @return Rediska_Pipeline
  195. */
  196. public function getRandomKey() { $args = func_get_args(); return $this->_addCommand('getRandomKey', $args); }
  197. /**
  198. * Rename the old key in the new one
  199. *
  200. * @param string $oldKey Old key name
  201. * @param string $newKey New key name
  202. * @param boolean[optional] $overwrite Overwrite the new name key if it already exists. For default is false.
  203. * @return Rediska_Pipeline
  204. */
  205. public function rename($oldKey, $newKey, $overwrite = true) { $args = func_get_args(); return $this->_addCommand('rename', $args); }
  206. /**
  207. * Get the number of keys
  208. *
  209. * @return Rediska_Pipeline
  210. */
  211. public function getKeysCount() { $args = func_get_args(); return $this->_addCommand('getKeysCount', $args); }
  212. /**
  213. * Set a time to live in seconds or timestamp on a key
  214. *
  215. * @param string $key Key name
  216. * @param integer $secondsOrTimestamp Time in seconds or timestamp
  217. * @param boolean $isTimestamp[optional] Time is timestamp. For default is false.
  218. * @return Rediska_Pipeline
  219. */
  220. public function expire($key, $secondsOrTimestamp, $isTimestamp = false) { $args = func_get_args(); return $this->_addCommand('expire', $args); }
  221. /**
  222. * Get key lifetime
  223. *
  224. * @param string $key Key name
  225. * @return Rediska_Pipeline
  226. */
  227. public function getLifetime($key) { $args = func_get_args(); return $this->_addCommand('getLifetime', $args); }
  228. /**
  229. * Select the DB having the specified index
  230. *
  231. * @param integer $index Db index
  232. * @return Rediska_Pipeline
  233. */
  234. public function selectDb($index) { $args = func_get_args(); return $this->_addCommand('selectDb', $args); }
  235. /**
  236. * Move the key from the currently selected DB to the DB having as index dbindex
  237. *
  238. * @param string $key Key name
  239. * @param integer $dbIndex Redis DB index
  240. * @return Rediska_Pipeline
  241. */
  242. public function moveToDb($key, $dbIndex) { $args = func_get_args(); return $this->_addCommand('moveToDb', $args); }
  243. /**
  244. * Remove all the keys of the currently selected DB
  245. *
  246. * @param boolean[optional] $all Remove from all Db. For default is false.
  247. * @return Rediska_Pipeline
  248. */
  249. public function flushDb($all = false) { $args = func_get_args(); return $this->_addCommand('flushDb', $args); }
  250. /**
  251. * Set value to a key or muliple values to multiple keys
  252. *
  253. * @param string|array $keyOrData Key name or array with key => value.
  254. * @param mixed $valueOrOverwrite[optional] Value or overwrite property for array of values. For default true.
  255. * @param boolean $overwrite[optional] Overwrite for single value (if false don't set and return false if key already exist). For default true.
  256. * @return Rediska_Pipeline
  257. */
  258. public function set($keyOrData, $valueOrOverwrite = null, $overwrite = true) { $args = func_get_args(); return $this->_addCommand('set', $args); }
  259. /**
  260. * Set + Expire atomic command
  261. *
  262. * @param string $key Key name
  263. * @param mixed $value Value
  264. * @param integer $seconds Expire time in seconds
  265. * @return Rediska_Pipeline
  266. */
  267. public function setAndExpire($key, $value, $seconds) { $args = func_get_args(); return $this->_addCommand('setAndExpire', $args); }
  268. /**
  269. * Atomic set value and return old
  270. *
  271. * @param string $key Key name
  272. * @param mixed $value Value
  273. * @return Rediska_Pipeline
  274. */
  275. public function setAndGet($key, $value) { $args = func_get_args(); return $this->_addCommand('setAndGet', $args); }
  276. /**
  277. * Get value of key or array of values by array of keys
  278. *
  279. * @param string|array $keyOrKeys Key name or array of names
  280. * @return Rediska_Pipeline
  281. */
  282. public function get($keyOrKeys) { $args = func_get_args(); return $this->_addCommand('get', $args); }
  283. /**
  284. * Append value to a end of string key
  285. *
  286. * @param string $key Key name
  287. * @param mixed $value Value
  288. * @return Rediska_Pipeline
  289. */
  290. public function append($key, $value) { $args = func_get_args(); return $this->_addCommand('append', $args); }
  291. /**
  292. * Increment the number value of key by integer
  293. *
  294. * @param string $key Key name
  295. * @param integer[optional] $amount Amount to increment. One for default
  296. * @return Rediska_Pipeline
  297. */
  298. public function increment($key, $amount = 1) { $args = func_get_args(); return $this->_addCommand('increment', $args); }
  299. /**
  300. * Decrement the number value of key by integer
  301. *
  302. * @param string $key Key name
  303. * @param integer[optional] $amount Amount to decrement. One for default
  304. * @return Rediska_Pipeline
  305. */
  306. public function decrement($key, $amount = 1) { $args = func_get_args(); return $this->_addCommand('decrement', $args); }
  307. /**
  308. * Overwrite part of a string at key starting at the specified offset
  309. *
  310. * @param string $key Key name
  311. * @param integer $offset Offset
  312. * @param integer $value Value
  313. * @return Rediska_Pipeline
  314. */
  315. public function setRange($key, $offset, $value) { $args = func_get_args(); return $this->_addCommand('setRange', $args); }
  316. /**
  317. * Return a subset of the string from offset start to offset end (both offsets are inclusive)
  318. *
  319. * @param string $key Key name
  320. * @param integer $start Start
  321. * @param integer[optional] $end End. If end is omitted, the substring starting from $start until the end of the string will be returned. For default end of string
  322. * @return Rediska_Pipeline
  323. */
  324. public function getRange($key, $start, $end = -1) { $args = func_get_args(); return $this->_addCommand('getRange', $args); }
  325. /**
  326. * Return a subset of the string from offset start to offset end (both offsets are inclusive)
  327. *
  328. * @param string $key Key name
  329. * @param integer $start Start
  330. * @param integer[optional] $end End. If end is omitted, the substring starting from $start until the end of the string will be returned. For default end of string
  331. * @return Rediska_Pipeline
  332. */
  333. public function substring($key, $start, $end = -1) { $args = func_get_args(); return $this->_addCommand('substring', $args); }
  334. /**
  335. * Returns the bit value at offset in the string value stored at key
  336. *
  337. * @param string $key Key name
  338. * @param integer $offset Offset
  339. * @param integer $bit Bit (0 or 1)
  340. * @return Rediska_Pipeline
  341. */
  342. public function setBit($key, $offset, $bit) { $args = func_get_args(); return $this->_addCommand('setBit', $args); }
  343. /**
  344. * Returns the bit value at offset in the string value stored at key
  345. *
  346. * @param string $key Key name
  347. * @param integer $offset Offset
  348. * @return Rediska_Pipeline
  349. */
  350. public function getBit($key, $offset) { $args = func_get_args(); return $this->_addCommand('getBit', $args); }
  351. /**
  352. * Returns the length of the string value stored at key
  353. *
  354. * @param string $key Key name
  355. * @return Rediska_Pipeline
  356. */
  357. public function getLength($key) { $args = func_get_args(); return $this->_addCommand('getLength', $args); }
  358. /**
  359. * Append value to the end of List
  360. *
  361. * @param string $key Key name
  362. * @param mixed $value Element value
  363. * @param boolean[optional] $createIfNotExists Create list if not exists
  364. * @return Rediska_Pipeline
  365. */
  366. public function appendToList($key, $value, $createIfNotExists = true) { $args = func_get_args(); return $this->_addCommand('appendToList', $args); }
  367. /**
  368. * Append value to the head of List
  369. *
  370. * @param string $key Key name
  371. * @param mixed $value Element value
  372. * @param boolean[optional] $createIfNotExists Create list if not exists
  373. * @return Rediska_Pipeline
  374. */
  375. public function prependToList($key, $value, $createIfNotExists = true) { $args = func_get_args(); return $this->_addCommand('prependToList', $args); }
  376. /**
  377. * Return the length of the List value at key
  378. *
  379. * @param string $key Key name
  380. * @return Rediska_Pipeline
  381. */
  382. public function getListLength($key) { $args = func_get_args(); return $this->_addCommand('getListLength', $args); }
  383. /**
  384. * Get List by key
  385. *
  386. * @param string $key Key name
  387. * @param integer $start[optional] Start index. For default is begin of list
  388. * @param integer $end[optional] End index. For default is end of list
  389. * @param boolean $responseIterator[optional] If true - command return iterator which read from socket buffer.
  390. * Important: new connection will be created
  391. * @return Rediska_Pipeline
  392. */
  393. public function getList($key, $start = 0, $end = -1, $responseIterator = false) { $args = func_get_args(); return $this->_addCommand('getList', $args); }
  394. /**
  395. * Trim the list at key to the specified range of elements
  396. *
  397. * @param string $key Key name
  398. * @param integer $start Start index
  399. * @param integer $end End index
  400. * @return Rediska_Pipeline
  401. */
  402. public function truncateList($key, $start, $end) { $args = func_get_args(); return $this->_addCommand('truncateList', $args); }
  403. /**
  404. * Return element of List by index at key
  405. *
  406. * @param string $key Key name
  407. * @param integer $index Index
  408. * @return Rediska_Pipeline
  409. */
  410. public function getFromList($key, $index) { $args = func_get_args(); return $this->_addCommand('getFromList', $args); }
  411. /**
  412. * Set a new value as the element at index position of the List at key
  413. *
  414. * @param string $key Key name
  415. * @param mixed $value Value
  416. * @param integer $index Index
  417. * @return Rediska_Pipeline
  418. */
  419. public function setToList($key, $index, $member) { $args = func_get_args(); return $this->_addCommand('setToList', $args); }
  420. /**
  421. * Delete element from list by member at key
  422. *
  423. * @param $key Key name
  424. * @param $value Element value
  425. * @param $count[optional] Limit of deleted items. For default no limit.
  426. * @return Rediska_Pipeline
  427. */
  428. public function deleteFromList($key, $value, $count = 0) { $args = func_get_args(); return $this->_addCommand('deleteFromList', $args); }
  429. /**
  430. * Return and remove the first element of the List at key
  431. *
  432. * @param string $key Key name
  433. * @return Rediska_Pipeline
  434. */
  435. public function shiftFromList($key) { $args = func_get_args(); return $this->_addCommand('shiftFromList', $args); }
  436. /**
  437. * Return and remove the first element of the List at key and block if list is empty or not exists
  438. *
  439. * @param string $keyOrKeys Key name or array of names
  440. * @param string $timeout Blocking timeout in seconds. Timeout disabled for default.
  441. * @return Rediska_Pipeline
  442. */
  443. public function shiftFromListBlocking($keyOrKeys, $timeout = 0) { $args = func_get_args(); return $this->_addCommand('shiftFromListBlocking', $args); }
  444. /**
  445. * Return and remove the last element of the List at key
  446. *
  447. * @param string $name Key name
  448. * @param string[optional] $pushToName If not null - push value to another key.
  449. * @return Rediska_Pipeline
  450. */
  451. public function popFromList($key, $pushToKey = null) { $args = func_get_args(); return $this->_addCommand('popFromList', $args); }
  452. /**
  453. * Return and remove the last element of the List at key and block if list is empty or not exists
  454. *
  455. * @param string|array $keyOrKeys Key name or array of names
  456. * @param integer $timeout[optional] Timeout. 0 for default - timeout is disabled.
  457. * @param string $pushToKey[optional] If not null - push value to another list.
  458. * @return Rediska_Pipeline
  459. */
  460. public function popFromListBlocking($keyOrKeys, $timeout = 0, $pushToKey = null) { $args = func_get_args(); return $this->_addCommand('popFromListBlocking', $args); }
  461. /**
  462. * Insert a new value as the element before or after the reference value
  463. *
  464. * @param string $key Key name
  465. * @param string $position BEFORE or AFTER
  466. * @param mixed $referenceValue Reference value
  467. * @param mixed $value Value
  468. * @return Rediska_Pipeline
  469. */
  470. public function insertToList($key, $position, $referenceValue, $value) { $args = func_get_args(); return $this->_addCommand('insertToList', $args); }
  471. /**
  472. * Insert a new value as the element after the reference value
  473. *
  474. * @param string $key Key name
  475. * @param mixed $referenceValue Reference value
  476. * @param mixed $value Value
  477. * @return Rediska_Pipeline
  478. */
  479. public function insertToListAfter($key, $referenceValue, $value) { $args = func_get_args(); return $this->_addCommand('insertToListAfter', $args); }
  480. /**
  481. * Insert a new value as the element before the reference value
  482. *
  483. * @param string $key Key name
  484. * @param mixed $referenceValue Reference value
  485. * @param mixed $value Value
  486. * @return Rediska_Pipeline
  487. */
  488. public function insertToListBefore($key, $referenceValue, $value) { $args = func_get_args(); return $this->_addCommand('insertToListBefore', $args); }
  489. /**
  490. * Add the specified member to the Set value at key
  491. *
  492. * @param string $key Key name
  493. * @param mixed $member Member
  494. * @return Rediska_Pipeline
  495. */
  496. public function addToSet($key, $member) { $args = func_get_args(); return $this->_addCommand('addToSet', $args); }
  497. /**
  498. * Remove the specified member from the Set value at key
  499. *
  500. * @param string $key Key name
  501. * @param mixed $member Member
  502. * @return Rediska_Pipeline
  503. */
  504. public function deleteFromSet($key, $member) { $args = func_get_args(); return $this->_addCommand('deleteFromSet', $args); }
  505. /**
  506. * Get random element from the Set value at key
  507. *
  508. * @param string $key Key name
  509. * @param boolean[optional] $pop If true - pop value from the set. For default is false
  510. * @return Rediska_Pipeline
  511. */
  512. public function getRandomFromSet($key, $pop = false) { $args = func_get_args(); return $this->_addCommand('getRandomFromSet', $args); }
  513. /**
  514. * Return the number of elements (the cardinality) of the Set at key
  515. *
  516. * @param string $key Key name
  517. * @return Rediska_Pipeline
  518. */
  519. public function getSetLength($key) { $args = func_get_args(); return $this->_addCommand('getSetLength', $args); }
  520. /**
  521. * Test if the specified value is a member of the Set at key
  522. *
  523. * @param string $key Key value
  524. * @param mixed $member Member
  525. * @return Rediska_Pipeline
  526. */
  527. public function existsInSet($key, $member) { $args = func_get_args(); return $this->_addCommand('existsInSet', $args); }
  528. /**
  529. * Return the intersection between the Sets stored at key1, key2, ..., keyN
  530. *
  531. * @param array $keys Array of key names
  532. * @param string[optional] $storeKey Store to set with key name
  533. * @return Rediska_Pipeline
  534. */
  535. public function intersectSets(array $keys, $storeKey = null) { $args = func_get_args(); return $this->_addCommand('intersectSets', $args); }
  536. /**
  537. * Return the union between the Sets stored at key1, key2, ..., keyN
  538. *
  539. * @param array $keys Array of key names
  540. * @param string[optional] $storeKey Store to set with key name
  541. * @return Rediska_Pipeline
  542. */
  543. public function unionSets(array $keys, $storeKey = null) { $args = func_get_args(); return $this->_addCommand('unionSets', $args); }
  544. /**
  545. * Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
  546. *
  547. * @param array $keys Array of key names
  548. * @param string[optional] $storeKey Store to set with key name
  549. * @return Rediska_Pipeline
  550. */
  551. public function diffSets(array $keys, $storeKey = null) { $args = func_get_args(); return $this->_addCommand('diffSets', $args); }
  552. /**
  553. * Return all the members of the Set value at key
  554. *
  555. * @param string $key Key name
  556. * @param boolean $responseIterator[optional] If true - command return iterator which read from socket buffer.
  557. * Important: new connection will be created
  558. * @return Rediska_Pipeline
  559. */
  560. public function getSet($key, $responseIterator = false) { $args = func_get_args(); return $this->_addCommand('getSet', $args); }
  561. /**
  562. * Move the specified member from one Set to another atomically
  563. *
  564. * @param string $fromKey From key name
  565. * @param string $toKey To key name
  566. * @param mixed $member Member
  567. * @return Rediska_Pipeline
  568. */
  569. public function moveToSet($fromKey, $toKey, $member) { $args = func_get_args(); return $this->_addCommand('moveToSet', $args); }
  570. /**
  571. * Add member to sorted set
  572. *
  573. * @param string $key Key name
  574. * @param mixed $member Member
  575. * @param number $score Score of member
  576. * @return Rediska_Pipeline
  577. */
  578. public function addToSortedSet($key, $member, $score) { $args = func_get_args(); return $this->_addCommand('addToSortedSet', $args); }
  579. /**
  580. * Delete the specified member from the sorted set by value
  581. *
  582. * @param string $key Key name
  583. * @param mixed $member Member
  584. * @return Rediska_Pipeline
  585. */
  586. public function deleteFromSortedSet($key, $member) { $args = func_get_args(); return $this->_addCommand('deleteFromSortedSet', $args); }
  587. /**
  588. * Get all the members of the Sorted Set value at key
  589. *
  590. * @param string $key Key name
  591. * @param integer $withScores[optional] Return values with scores. For default is false.
  592. * @param integer $start[optional] Start index. For default is begin of set.
  593. * @param integer $end[optional] End index. For default is end of set.
  594. * @param boolean $revert[optional] Revert elements (not used in sorting). For default is false
  595. * @param boolean $responseIterator[optional] If true - command return iterator which read from socket buffer.
  596. * Important: new connection will be created
  597. * @return Rediska_Pipeline
  598. */
  599. public function getSortedSet($key, $withScores = false, $start = 0, $end = -1, $revert = false, $responseIterator = false) { $args = func_get_args(); return $this->_addCommand('getSortedSet', $args); }
  600. /**
  601. * Get members from sorted set by min and max score
  602. *
  603. * @param string $key Key name
  604. * @param number $min Min score
  605. * @param number $max Max score
  606. * @param boolean[optional] $withScores Get with scores. For default is false
  607. * @param integer[optional] $limit Limit. For default is no limit
  608. * @param integer[optional] $offset Offset. For default is no offset
  609. * @return Rediska_Pipeline
  610. */
  611. public function getFromSortedSetByScore($key, $min, $max, $withScores = false, $limit = null, $offset = null) { $args = func_get_args(); return $this->_addCommand('getFromSortedSetByScore', $args); }
  612. /**
  613. * Get length of Sorted Set
  614. *
  615. * @param string $key Key name
  616. * @return Rediska_Pipeline
  617. */
  618. public function getSortedSetLength($key) { $args = func_get_args(); return $this->_addCommand('getSortedSetLength', $args); }
  619. /**
  620. * Get count of members from sorted set by min and max score
  621. *
  622. * @param string $key Key name
  623. * @param number $min Min score
  624. * @param number $max Max score
  625. * @return Rediska_Pipeline
  626. */
  627. public function getSortedSetLengthByScore($key, $min, $max) { $args = func_get_args(); return $this->_addCommand('getSortedSetLengthByScore', $args); }
  628. /**
  629. * Increment score of sorted set element
  630. *
  631. * @param string $key Key name
  632. * @param mixed $value Member
  633. * @param integer|float $score Score to increment
  634. * @return Rediska_Pipeline
  635. */
  636. public function incrementScoreInSortedSet($key, $value, $score) { $args = func_get_args(); return $this->_addCommand('incrementScoreInSortedSet', $args); }
  637. /**
  638. * Remove all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).
  639. *
  640. * @param string $key Key name
  641. * @param numeric $min Min value
  642. * @param numeric $max Max value
  643. * @return Rediska_Pipeline
  644. */
  645. public function deleteFromSortedSetByScore($key, $min, $max) { $args = func_get_args(); return $this->_addCommand('deleteFromSortedSetByScore', $args); }
  646. /**
  647. * Remove all elements in the sorted set at key with rank between start and end
  648. *
  649. * @param string $key Key name
  650. * @param numeric $start Start position
  651. * @param numeric $end End position
  652. * @return Rediska_Pipeline
  653. */
  654. public function deleteFromSortedSetByRank($key, $start, $end) { $args = func_get_args(); return $this->_addCommand('deleteFromSortedSetByRank', $args); }
  655. /**
  656. * Get member score from Sorted Set
  657. *
  658. * @param string $key Key name
  659. * @param mixed $member Member value
  660. * @return Rediska_Pipeline
  661. */
  662. public function getScoreFromSortedSet($key, $member) { $args = func_get_args(); return $this->_addCommand('getScoreFromSortedSet', $args); }
  663. /**
  664. * Get rank of member from sorted set
  665. *
  666. * @param string $key Key name
  667. * @param integer $member Member value
  668. * @param boolean $revert[optional] Revert elements (not used in sorting). For default is false
  669. * @return Rediska_Pipeline
  670. */
  671. public function getRankFromSortedSet($key, $member, $revert = false) { $args = func_get_args(); return $this->_addCommand('getRankFromSortedSet', $args); }
  672. /**
  673. * Store to key union between the sorted sets
  674. *
  675. * @param array $keys Array of key names or associative array with weights
  676. * @param string $storeKey Result sorted set key name
  677. * @param string $aggregation Aggregation method: SUM (for default), MIN, MAX.
  678. * @return Rediska_Pipeline
  679. */
  680. public function unionSortedSets(array $keys, $storeKey, $aggregation = Rediska_Command_UnionSortedSets::SUM) { $args = func_get_args(); return $this->_addCommand('unionSortedSets', $args); }
  681. /**
  682. * Store to key intersection between sorted sets
  683. *
  684. * @param array $keys Array of key names or associative array with weights
  685. * @param string $storeKey Result sorted set key name
  686. * @param string $aggregation Aggregation method: SUM (for default), MIN, MAX.
  687. * @return Rediska_Pipeline
  688. */
  689. public function intersectSortedSets(array $keys, $storeKey, $aggregation = Rediska_Command_IntersectSortedSets::SUM) { $args = func_get_args(); return $this->_addCommand('intersectSortedSets', $args); }
  690. /**
  691. * Set value to a hash field or fields
  692. *
  693. * @param string $key Key name
  694. * @param array|string $fieldOrData Field or array of many fields and values: field => value
  695. * @param mixed $value Value for single field
  696. * @param boolean $overwrite Overwrite for single field (if false don't set and return false if key already exist). For default true.
  697. * @return Rediska_Pipeline
  698. */
  699. public function setToHash($key, $fieldOrData, $value = null, $overwrite = true) { $args = func_get_args(); return $this->_addCommand('setToHash', $args); }
  700. /**
  701. * Get value from hash field or fields
  702. *
  703. * @param string $key Key name
  704. * @param string|array $fieldOrFields Field or fields
  705. * @return Rediska_Pipeline
  706. */
  707. public function getFromHash($key, $fieldOrFields) { $args = func_get_args(); return $this->_addCommand('getFromHash', $args); }
  708. /**
  709. * Increment field value in hash
  710. *
  711. * @param string $key Key name
  712. * @param mixed $field Field
  713. * @param number $amount[optional] Increment amount. One for default
  714. * @return Rediska_Pipeline
  715. */
  716. public function incrementInHash($key, $field, $amount = 1) { $args = func_get_args(); return $this->_addCommand('incrementInHash', $args); }
  717. /**
  718. * Test if field is present in hash
  719. *
  720. * @param string $key Key name
  721. * @param mixed $field Field
  722. * @return Rediska_Pipeline
  723. */
  724. public function existsInHash($key, $field) { $args = func_get_args(); return $this->_addCommand('existsInHash', $args); }
  725. /**
  726. * Delete field from hash
  727. *
  728. * @param string $key Key name
  729. * @param mixed $field Field
  730. * @return Rediska_Pipeline
  731. */
  732. public function deleteFromHash($key, $field) { $args = func_get_args(); return $this->_addCommand('deleteFromHash', $args); }
  733. /**
  734. * Return the number of fields in hash
  735. *
  736. * @param string $key Key name
  737. * @return Rediska_Pipeline
  738. */
  739. public function getHashLength($key) { $args = func_get_args(); return $this->_addCommand('getHashLength', $args); }
  740. /**
  741. * Get hash fields and values
  742. *
  743. * @param string $key Key name
  744. * @return Rediska_Pipeline
  745. */
  746. public function getHash($key) { $args = func_get_args(); return $this->_addCommand('getHash', $args); }
  747. /**
  748. * Get hash fields
  749. *
  750. * @param string $key Key name
  751. * @return Rediska_Pipeline
  752. */
  753. public function getHashFields($key) { $args = func_get_args(); return $this->_addCommand('getHashFields', $args); }
  754. /**
  755. * Get hash values
  756. *
  757. * @param string $key Key name
  758. * @return Rediska_Pipeline
  759. */
  760. public function getHashValues($key) { $args = func_get_args(); return $this->_addCommand('getHashValues', $args); }
  761. /**
  762. * Get sorted elements contained in the List, Set, or Sorted Set value at key.
  763. *
  764. * @param string $key Key name
  765. * @param array $value Options:
  766. * * order
  767. * * limit
  768. * * offset
  769. * * alpha
  770. * * get
  771. * * by
  772. * * store
  773. *
  774. * See more: http://code.google.com/p/redis/wiki/SortCommand
  775. * If you use more then one connection to Redis servers,
  776. * it will choose by key name, and key by you pattern's may not present on it.
  777. *
  778. * @return Rediska_Pipeline
  779. */
  780. public function sort($key, array $options = array()) { $args = func_get_args(); return $this->_addCommand('sort', $args); }
  781. /**
  782. * Publish message to pubsub channel
  783. *
  784. * @param array|string $channelOrChannels Channel or array of channels
  785. * @param mixed $message Message
  786. * @return Rediska_Pipeline
  787. */
  788. public function publish($channelOrChannels, $message) { $args = func_get_args(); return $this->_addCommand('publish', $args); }
  789. /**
  790. * Save the DB on disk
  791. *
  792. * @param boolean[optional] $background Save asynchronously. For default is false
  793. * @return Rediska_Pipeline
  794. */
  795. public function save($background = false) { $args = func_get_args(); return $this->_addCommand('save', $args); }
  796. /**
  797. * Return the UNIX time stamp of the last successfully saving of the dataset on disk
  798. *
  799. * @return Rediska_Pipeline
  800. */
  801. public function getLastSaveTime() { $args = func_get_args(); return $this->_addCommand('getLastSaveTime', $args); }
  802. /**
  803. * Stop all the clients, save the DB, then quit the server
  804. *
  805. * @return Rediska_Pipeline
  806. */
  807. public function shutdown() { $args = func_get_args(); return $this->_addCommand('shutdown', $args); }
  808. /**
  809. * Rewrite the Append Only File in background when it gets too big
  810. *
  811. * @return Rediska_Pipeline
  812. */
  813. public function rewriteAppendOnlyFile() { $args = func_get_args(); return $this->_addCommand('rewriteAppendOnlyFile', $args); }
  814. /**
  815. * Provide information and statistics about the server
  816. *
  817. * @return Rediska_Pipeline
  818. */
  819. public function info() { $args = func_get_args(); return $this->_addCommand('info', $args); }
  820. /**
  821. * Change the replication settings of a slave on the fly
  822. *
  823. * @param string|Rediska_Connection|false $aliasOrConnection Server alias, Rediska_Connection object or false if not slave
  824. * @return Rediska_Pipeline
  825. */
  826. public function slaveOf($aliasOrConnection) { $args = func_get_args(); return $this->_addCommand('slaveOf', $args); }
  827. }