Rediska

Follow me on twitter…

Sorted sets

Sorted sets are like sets, but their elements have position index.

Example

<?php

require_once 'Rediska/Key/SortedSet.php';
$sortedSet = new Rediska_Key_SortedSet('sortedSet');

$sortedSet[1] = 'first element';
$sortedSet[2] = 'second element';

echo count($sortedSet); #=> 2

echo isset($sortedSet[1]); #=> true

echo $sortedSet[1]; #=> first element

unset($sortedSet[2]);

// Iterate sorted set
foreach($sortedSet as $element) {
    echo $element;
}

?>

All methods

<?php

/**
 * Construct key
 * 
 * @param string  $name   Key name
 * @param integer $expire Expire time in seconds
 * @param string|null $serverAlias Server alias where key is placed
 */
public function __construct($name, $expire = null, $serverAlias = null)

/**
 * Add the specified member to the Sorted set
 * 
 * @param mixin $value Value
 * @param numeric $score Score
 * @return boolean
 */
public function add($value, $score)

/**
 * Remove the specified member from the Sorted set
 * 
 * @param mixin $value Value
 * @return boolean
 */
public function remove($value)

/**
 * Get Sorted set length
 * 
 * @return integer
 */
public function count()

/**
 * Get Sorted set by score
 * 
 * @param number  $min        Min score
 * @param number  $max        Max score
 * @param boolean $withScores Get with scores
 * @param integer $limit      Limit
 * @param integer $offset     Offset
 * @return array
 */
public function getByScore($min, $max, $withScores = false, $limit = null, $offset = null)

/**
 * Remove members from sorted set by score
 * 
 * @param $min Min score
 * @param $max Max score
 * @return integer
 */
public function removeByScore($min, $max)

/**
 * Get member score from Sorted Set
 * 
 * @param mixin $value
 * @return numeric
 */
public function getScore($value)

/**
 * Increment score of element
 * 
 * @param $value
 * @return integer
 */
public function incrementScore($value, $score)

/**
 * Remove all elements in the sorted set at key with rank between start and end
 * 
 * @param numeric $start Start position
 * @param numeric $end   End position
 * @return integer
 */ 
public function removeByRank($start, $end)

/**
 * Get rank of member
 * 
 * @param integer $value  Member value
 * @param boolean $revert Revert elements (not used in sorting)
 * @return integer
 */ 
public function getRank($value, $revert = false)

/**
 * Store to key union between the sorted sets
 * 
 * @param string|array  $setOrSets    Sorted set key name or object, or array of its
 * @param string        $storeKeyName Result sorted set key name
 * @param string        $aggregation  Aggregation method: SUM (for default), MIN, MAX.
 * @return integer
 */
public function union($setOrSets, $storeKeyName, $aggregation = 'sum')

/**
 * Store to key intersection between sorted sets
 * 
 * @param string|array  $setOrSets    Sorted set key name or object, or array of its
 * @param string        $storeKeyName Result sorted set key name
 * @param string        $aggregation  Aggregation method: SUM (for default), MIN, MAX.
 * @return integer
 */
public function intersect($setOrSets, $storeKeyName, $aggregation = 'sum')

/**
 * Get sorted the elements
 * 
 * @param string|array  $value Options or SORT query string (http://code.google.com/p/redis/wiki/SortCommand).
 *                             Important notes for SORT query string:
 *                                 1. If you set Rediska namespace option don't forget add it to key names.
 *                                 2. If you use more then one connection to Redis servers, it will choose by key name,
 *                                    and key by you pattern's may not present on it.
 * @return array
 */
public function sort($options = array())

/**
 * Get Sorted set values
 * 
 * @param integer $withScores  Return values with scores
 * @param integer $start       Start index
 * @param integer $end         End index
 * @param boolean $revert      Revert elements (not used in sorting)
 * @return array
 */
public function toArray($withScores = false, $start = 0, $end = -1, $revert = false)

/**
 * Add array to Sorted set
 * 
 * @param array $array
 */
public function fromArray(array $array)

/**
 * Delete key
 * 
 * @return boolean
 */
public function delete()

/**
 * Exists in db
 * 
 * @return boolean
 */
public function isExists()

/**
 * Get key type
 * 
 * @see Rediska#getType
 * @return string
 */
public function getType()

/**
 * Rename key
 * 
 * @param string  $newName
 * @param boolean $overwrite
 * @return boolean
 */
public function rename($newName, $overwrite = true)

/**
 * Expire key
 * 
 * @param integer $secondsOrTimestamp Time in seconds or timestamp
 * @param boolean $isTimestamp        Time is timestamp? Default is false.
 * @return boolean
 */
public function expire($secondsOrTimestamp, $isTimestamp = false)

/**
 * Get key lifetime
 * 
 * @return integer
 */
public function getLifetime()

/**
 * Move key to other Db
 * 
 * @see Rediska#moveToDb
 * @param integer $dbIndex
 * @return boolean
 */
public function moveToDb($dbIndex)

/**
 * Get key name
 * 
 * @return string
 */
public function getName()

/**
 * Set key name
 * 
 * @param string $name
 * @return Rediska_Key_Abstract
 */
public function setName($name)

/**
 * Set expire time
 * 
 * @param $secondsOrTimestamp Time in seconds or timestamp
 * @param $isTimestamp        Time is timestamp? Default is false.
 * @return Rediska_Key_Abstract
 */
public function setExpire($secondsOrTimestamp, $isTimestamp = false)

/**
 * Get expire seconds or timestamp
 * 
 * @return integer
 */
public function getExpire()

/**
 * Is expire is timestamp
 * 
 * @return boolean
 */
public function isExpireTimestamp()

/**
 * Set server alias
 * 
 * @param $serverAlias
 * @return Rediska_Key_Abstract
 */
public function setServerAlias($serverAlias)

/**
 * Get server alias
 * 
 * @return null|string
 */
public function getServerAlias()

/**
 * Set Rediska instance
 * 
 * @param Rediska $rediska
 * @return Rediska_Key_Abstract
 */
public function setRediska(Rediska $rediska)

/**
 * Get Rediska instance
 * 
 * @return Rediska
 */
public function getRediska()

?>

Comments