Skip to content

Commit

Permalink
Clarify RedisCall::expire docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsur committed Jul 11, 2020
1 parent fc78e79 commit 6a40162
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/RedisCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,25 @@ final public function del($keys) {
/**
* expire
*
* Sets an expiration date (a timeout) on an item.
* Sets for how many seconds longer until a key disappers.
*
* As for the accuracy, per docs:
*
* @code
* In Redis 2.4 the expire might not be pin-point accurate, and
* it could be between zero to one seconds out.
*
* Since Redis 2.6 the expire error is from 0 to 1 milliseconds.
* @endcode
*
* The former may still be the case if redis backend is 2.4. Handle
* with care, especially if you use this library for time-precise
* operations.
*
* @param string $key The key that will disappear.
* @param integer $ttl The key's remaining ttl, in seconds.
* @return bool True on success, false otherwise.
* @see https://archive.fo/ixbKW
*/
final public function expire(string $key, int $ttl) {
$res = $this->connection->expire($key, $ttl);
Expand Down Expand Up @@ -198,8 +212,8 @@ final public function ttl(string $key) {
/**
* time
*
* Get Redis server time. Always use server time as a reference to
* do RedisConn::expireat in case of PHP interpreter's or Redis
* Get redis server time. Always use server time as a reference to
* do RedisConn::expireat in case of PHP interpreter's or redis
* server's clock not being properly synched.
*
* @param bool $with_mcs If true, returned time includes microsecond
Expand Down
5 changes: 4 additions & 1 deletion tests/RedisConnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ public function test_expire() {
$eq = self::eq();

$conn->set('key1', 'val1');
# set expire in the past
# set expire in 1 second
$conn->expire('key1', 1);
# wait for 2 seconds for the key to properly destroyed due
# to unreliable expire accuracy; causes the tests to
# visibly freeze for a while
sleep(2);
$ret = $conn->get('key1');
$eq($ret, false);
Expand Down

0 comments on commit 6a40162

Please sign in to comment.