From bd5a1b42ebbc68a6d864c7434e6d71d1c6baa7e0 Mon Sep 17 00:00:00 2001 From: Jacob Christiansen Date: Fri, 27 Mar 2015 11:29:32 +0100 Subject: [PATCH] Set correct expire timestamp --- lib/Store/Redis.php | 4 ++-- test/Store/RedisTest.php | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Store/Redis.php b/lib/Store/Redis.php index b25aad8..05bcf5d 100644 --- a/lib/Store/Redis.php +++ b/lib/Store/Redis.php @@ -57,9 +57,9 @@ public function set($type, $key, $value, $expire = null) $this->redis->set($redisKey, serialize($value)); if (is_null($expire)) { - $expire = $this->lifeTime; + $expire = time() + $this->lifeTime; } - $this->redis->expire($redisKey, $expire); + $this->redis->expireat($redisKey, $expire); } /** diff --git a/test/Store/RedisTest.php b/test/Store/RedisTest.php index 78b12c5..51317ab 100644 --- a/test/Store/RedisTest.php +++ b/test/Store/RedisTest.php @@ -26,7 +26,7 @@ public function set($key, $value) self::$setValue = $value; } - public function expire($key, $expire) + public function expireat($key, $expire) { self::$expireKey = $key; self::$expireValue = $expire; @@ -93,7 +93,11 @@ public function testSetKeyInRedis() $this->assertEquals('simpleSAMLphp.test.key', Predis\Client::$setKey); $this->assertEquals(serialize(['one', 'two']), Predis\Client::$setValue); $this->assertEquals('simpleSAMLphp.test.key', Predis\Client::$expireKey); - $this->assertEquals(288000, Predis\Client::$expireValue); + /** + * Cannot be tested, because time is used and code is not in + * namespace, so the normal trick does not work. + */ + //$this->assertEquals(1427739616, \Predis\Client::$expireValue); } public function testSetKeyWithExpireInRedis()