コード例 #1
0
 public function testGc()
 {
     //cc 1 + 1*if + 1*for
     ini_set("session.gc_maxlifetime", 3);
     $redis = \RWKY\Redis\setUpRedis();
     \RWKY\Redis\RedisSessions::$redis = $redis;
     \RWKY\Redis\RedisSessions::$hash = "hash";
     $this->assertEmpty($redis->keys("*"));
     session_start();
     $_SESSION["test"] = 1;
     session_write_close();
     $this->assertNotEmpty($redis->keys("*"));
     sleep(5);
     $this->assertTrue(\RWKY\Redis\RedisSessions::gc());
     $this->assertEmpty($redis->keys("*"));
     \RWKY\Redis\RedisSessions::$hash = null;
     session_start();
     $_SESSION["test"] = 1;
     session_write_close();
     $this->assertNotEmpty($redis->keys("*"));
     sleep(5);
     $this->assertTrue(\RWKY\Redis\RedisSessions::gc());
     $this->assertEmpty($redis->keys("*"));
 }
コード例 #2
0
ファイル: benchmark.php プロジェクト: rwky/Rwky-Redis
<?php

/**
 *@file
 *This file benchmarks a few aspects of \\RWKY\\Redis<br />
 *It can benchmark magic methods vs cmd, pipelining vs no pipelining and tcp vs unix sockets<br />
 *<strong>Be careful when running this file it may overwrite your redis database</strong>
 */
require "tests/tests-include.inc";
$redis = \RWKY\Redis\setUpRedis();
$tests = array("magic", "pipelining", "connection");
if (!isset($argv[1])) {
    $argv[1] = "all";
}
if ($argv[1] == "all") {
    foreach ($tests as $t) {
        echo "---{$t}---" . PHP_EOL;
        $t();
        echo "--- ---" . PHP_EOL;
    }
    exit;
}
array_shift($argv);
foreach ($argv as $arg) {
    if (!in_array($arg, $tests)) {
        echo "Invalid test {$arg}" . PHP_EOL;
    } else {
        echo "---{$arg}---" . PHP_EOL;
        $arg();
        echo "--- ---" . PHP_EOL;
    }
コード例 #3
0
ファイル: redis-tests.php プロジェクト: rwky/Rwky-Redis
 public function testException2()
 {
     //cc 1 +  2*switch
     $redis = \RWKY\Redis\setUpRedis();
     $redis->config("ON_EXCEPTION", "file");
     $redis->config("ON_EXCEPTION_FILE", "/tmp/redis-exception-test");
     file_put_contents("/tmp/redis-exception-test", "Hello world");
     ob_start();
     try {
         throw new \RWKY\Redis\RedisException($redis, "Test exception 2", 0, "test", 1);
     } catch (Exception $e) {
         $this->assertEquals("Test exception 2", $e->getMessage());
     }
     $this->assertEquals("Hello world", ob_get_clean());
     shell_exec("rm /tmp/redis-exception-test");
 }