Daniele Alessandri 15 жил өмнө
parent
commit
2f6b24c098

+ 2 - 0
test/PredisShared.php

@@ -21,7 +21,9 @@ class RC {
     const EXCEPTION_NO_SUCH_KEY    = 'no such key';
     const EXCEPTION_NO_SUCH_KEY    = 'no such key';
     const EXCEPTION_OUT_OF_RANGE   = 'index out of range';
     const EXCEPTION_OUT_OF_RANGE   = 'index out of range';
     const EXCEPTION_INVALID_DB_IDX = 'invalid DB index';
     const EXCEPTION_INVALID_DB_IDX = 'invalid DB index';
+    const EXCEPTION_VALUE_NOT_INT  = 'value is not an integer';
     const EXCEPTION_EXEC_NO_MULTI  = 'EXEC without MULTI';
     const EXCEPTION_EXEC_NO_MULTI  = 'EXEC without MULTI';
+    const EXCEPTION_SETEX_TTL      = 'invalid expire time in SETEX';
 
 
     private static $_connection;
     private static $_connection;
 
 

+ 20 - 0
test/RedisCommandsTest.php

@@ -321,6 +321,26 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertEquals(-1, $this->redis->ttl('foo'));
         $this->assertEquals(-1, $this->redis->ttl('foo'));
     }
     }
 
 
+    function testSetExpire() {
+        $this->assertTrue($this->redis->setex('foo', 10, 'bar'));
+        $this->assertTrue($this->redis->exists('foo'));
+        $this->assertEquals(10, $this->redis->ttl('foo'));
+
+        $this->assertTrue($this->redis->setex('hoge', 1, 'piyo'));
+        sleep(2);
+        $this->assertFalse($this->redis->exists('hoge'));
+
+        RC::testForServerException($this, RC::EXCEPTION_VALUE_NOT_INT, function($test) {
+            $test->redis->setex('hoge', 2.5, 'piyo');
+        });
+        RC::testForServerException($this, RC::EXCEPTION_SETEX_TTL, function($test) {
+            $test->redis->setex('hoge', 0, 'piyo');
+        });
+        RC::testForServerException($this, RC::EXCEPTION_SETEX_TTL, function($test) {
+            $test->redis->setex('hoge', -10, 'piyo');
+        });
+    }
+
     function testDatabaseSize() {
     function testDatabaseSize() {
         // TODO: is this really OK?
         // TODO: is this really OK?
         $this->assertEquals(0, $this->redis->dbsize());
         $this->assertEquals(0, $this->redis->dbsize());