fix: use fixed ttl

This commit is contained in:
Reasno 2020-12-24 19:17:21 +08:00 committed by 李铭昕
parent 795199d5df
commit c4cd77fb0a
2 changed files with 3 additions and 4 deletions

View File

@ -78,7 +78,7 @@ class RedisAdapter implements AdapterInterface, EphemeralInterface
foreach ($rooms as $room) {
$this->redis->sAdd($this->getRoomKey($room), $sid);
if ($this->ttl > 0) {
$this->redis->zAdd($this->getExpireKey(), (int) (microtime(true) * 1000) + $this->ttl, $sid);
$this->redis->zAdd($this->getExpireKey(), microtime(true) * 1000 + $this->ttl, $sid);
}
}
$this->redis->sAdd($this->getStatKey(), $sid);
@ -226,7 +226,7 @@ class RedisAdapter implements AdapterInterface, EphemeralInterface
public function renew(string $sid): void
{
if ($this->ttl > 0) {
$this->redis->zIncrBy($this->getExpireKey(), $this->ttl, $sid);
$this->redis->zAdd($this->getExpireKey(), microtime(true) * 1000 + $this->ttl, $sid);
}
}

View File

@ -135,8 +135,7 @@ class RoomAdapterTest extends AbstractTestCase
$room->setTtl(1);
$room->add('renewed', 'foo');
$room->renew('renewed');
$room->renew('renewed');
usleep(1000);
usleep(500);
$room->cleanUpExpiredOnce();
$this->assertContains('renewed', $room->clients('foo'));