<?xml version="1.0" encoding="UTF-8"?>
<document>
  <body>&lt;p&gt;Single-value key is a basic Redis structure. Rediska provides object-oriented way to work with keys.&lt;/p&gt;
&lt;h3&gt;Example&lt;/h3&gt;
&lt;code&gt;
// Initialize key with name &quot;keyName&quot;
require_once 'Rediska/Key.php';
$key = new Rediska_Key('keyName');

// Set value
$key-&gt;setValue('value');

// Get value
$value = $key-&gt;getValue();

// Delete key
$key-&gt;delete();
&lt;/code&gt;
&lt;h3&gt;&quot;getOrSetValue&quot; magic method&lt;/h3&gt;
&lt;p&gt;Also &lt;span class=&quot;pre&quot;&gt;Rediska_Key&lt;/span&gt; provides a handy proxying method to set new value if key is not currently set:&lt;/p&gt;
&lt;code&gt;

// Initialize key with expire 2 minutes
require_once 'Rediska/Key.php';
$key = new Rediska_Key('keyName', 60 * 2);

// Old way
$value = $key-&gt;getValue();
if ($value === null) {
    $value = $exampleObject-&gt;getNewValue();
    $key-&gt;setValue($value);
}

// New way
$value = $key-&gt;getOrSetValue($exampleObject)-&gt;getNewValue();

// You can also get and set value from object's propery
$value = $key-&gt;getOrSetValue($exampleObject)-&gt;newValue;
// or set the returning value of function (time() for example)
$value = $key-&gt;getOrSetValue()-&gt;time();
&lt;/code&gt;
&lt;h3&gt;All methods&lt;/h3&gt;
&lt;code&gt;
/**
 * Construct key
 * 
 * @param string  $name   Key name
 * @param integer $expire Expire time in seconds
 */
public function __construct($name, $expire = null)

/**
 * Set key value
 * 
 * @param $value
 * @return boolean
 */
public function setValue($value)

/**
 * Get key value
 * 
 * @return mixin
 */
public function getValue()

/**
 * Get value, if value not present set it from chain method
 * 
 * @param $object Object of chain method
 */
public function getOrSetValue($object = null)

/**
 * 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 $seconds
 * @return boolean
 */
public function expire($seconds)

/**
 * 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 Rediska instance
 * 
 * @param Rediska $rediska
 * @return Rediska_Key_Abstract
 */
public function setRediska(Rediska $rediska)

/**
 * Get Rediska instance
 * 
 * @return Rediska
 */
public function getRediska()
&lt;/code&gt;</body>
  <cached-slug>single-value-keys</cached-slug>
  <comments-count type="integer">0</comments-count>
  <created-at type="datetime">2010-01-21T21:47:47Z</created-at>
  <id type="integer">10</id>
  <lft type="integer">16</lft>
  <parent-id type="integer">9</parent-id>
  <rgt type="integer">17</rgt>
  <title>Single-value keys</title>
  <updated-at type="datetime">2010-01-23T13:17:21Z</updated-at>
  <user-id type="integer">1</user-id>
</document>
