Skip to content

Commit

Permalink
add expire to Rediska_Key
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Mar 5, 2011
1 parent 1343e55 commit 4aeb9ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version 0.5.5 (March 2, 2011):
Version 0.5.5 (March 8, 2011):
* Feature #4214: Profiler
* Feature #9921: Implement SETBIT, GETBIT, SETRANGE, GETRANGE, STRLEN
* Feature #9932: Implement LINSERT, LPUSHX, RPUSHX
Expand All @@ -16,6 +16,7 @@ Version 0.5.5 (March 2, 2011):
* Improvement #9021: Add getByRank to Rediska_Key_SortedSet
* Improvement #9045: Add getFieldsAndValues() to Rediska_Key_Hash
* Improvement #9052: Add getValues to Rediska_Key_Set and Rediska_Key_List
* Improvement #10093: Add expire argument to Rediska_Key::getOrSetValue
* Bug #4900: Require Rediska bug in Rediska_PubSub_Channel
* Bug #6745: Pub/sub channel can't get Rediska_Connections
* Bug #10061: Subscribe throws exception by timeout if it not specified
Expand Down
38 changes: 31 additions & 7 deletions library/Rediska/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ public function getLength()

/**
* Get value, if value not present set it from chain method
*
* @param $object Object of chain method
*
* @param mixin[optional] $object Object of chain method
* @param integer[optional] $expire Expire
* @param boolean[optional] $expireIsTimestamp If true $expire argument in seconds, or $expire is timestamp
* @return Rediska_Key_GetOrSetValue
*/
public function getOrSetValue($object = null)
public function getOrSetValue($object = null, $expire = null, $expireIsTimestamp = false)
{
return new Rediska_Key_GetOrSetValue($this, $object);
return new Rediska_Key_GetOrSetValue($this, $object, $expire, $expireIsTimestamp);
}

/**
Expand Down Expand Up @@ -245,16 +248,34 @@ class Rediska_Key_GetOrSetValue
*/
protected $_object;

/**
* Expire
*
* @var integer
*/
protected $_expire;

/**
* Is expire in seconds
*
* @var bool
*/
protected $_expireIsTimestamp = false;

/**
* Construct GetOrSetValue provider
*
* @param Rediska_Key $key
* @param object $object Provider object
* @param integer[optional] $expire Expire
* @param boolean[optional] $expireIsTimestamp If true $expire argument in seconds, or $expire is timestamp
*/
public function __construct(Rediska_Key $key, $object = null)
public function __construct(Rediska_Key $key, $object = null, $expire = null, $expireIsTimestamp = false)
{
$this->_key = $key;
$this->_object = $object;
$this->_key = $key;
$this->_object = $object;
$this->_expire = $expire;
$this->_expireIsTimestamp = $expireIsTimestamp;
}

public function __call($method, $args)
Expand All @@ -269,6 +290,9 @@ public function __call($method, $args)
}
$value = call_user_func_array($callback, $args);
$this->_key->setValue($value);
if ($this->_expire !== null) {
$this->_key->expire($this->_expire, $this->_expireIsTimestamp);
}
}

return $value;
Expand Down

0 comments on commit 4aeb9ad

Please sign in to comment.