Lists
Good news, you can work with Redis lists as with native PHP arrays:
<?php require_once 'Rediska/Key/List.php'; $list = new Rediska_Key_List('list'); $list[] = 'first element'; $list[] = 'second element'; echo $list[1]; #=> 'second element'; $list[0] = 'new first element'; echo count($list); #=> 2 echo isset($list[0]); #=> true // Iterate list foreach($list 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) /** * Append value to the end of List * * @param mixin $value Value * @return boolean */ public function append($value) /** * Append value to the head of List * * @param mixin $value Value * @return boolean */ public function prepend($value) /** * Get List length * * @return integer */ public function count() /** * Trim the list at key to the specified range of elements * * @param integer $start Start index * @param integer $end End index * @return boolean */ public function truncate($limit, $offset = 0) /** * Return element of List by index * * @param integer $index Index * @return mixin */ public function get($index) /** * Set a new value as the element at index position of the List * * @param mixin $value Value * @param integer $index Index * @return boolean */ public function set($index, $value) /** * Delete element from list by value * * @throws Rediska_Exception * @param $value Element value * @param $count Limit of deleted items * @return integer */ public function remove($value, $count = 0) /** * Return and remove the first element of the List * * @return mixin */ public function shift() /** * Return and remove the last element of the List * * @return mixin */ public function pop() /** * 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 List values * * @param integer $start Start index * @param integer $end End index * @return array */ public function toArray($start = 0, $end = -1) /** * Add array to List * * @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() ?>