_instance(); } protected function _instance() { static $_instance; if(empty($_instance)) $_instance = $this->connect(); return $_instance; } function connect() { $this->db = new redis(); $this->db->connect('127.0.0.1', '6379'); $this->connect ++; return $this; } function __call($method, $args) { return call_user_func_array(array($this->db, $method) , $args); } } $redis = new cache(); $key_pre = time(); echo "pre : $key_pre\n"; //测试百万次循环 $s = microtime(true); while($total < 1000000) { $total++; } $e = microtime(true); printf("1 000 000 loop cost %4f\n", $e-$s); //测试百万次写入 $total = 0; $s = microtime(true); while($total <= 1000000) { $redis->set("$key_pre:{$total}", $total); $total++; } $e = microtime(true); printf("1 000 000 set cost %4f, lastkey: %s\n", $e-$s, "$key_pre:{$total}"); //测试百万次读取 $total = 0; $s = microtime(true); while($total <= 1000000) { $redis->get( "$key_pre:{$total}" ); $total++; } $e = microtime(true); printf("1 000 000 get cost %4f, lastkey: %s\n", $e-$s, "$key_pre:{$total}"); //测试百万级 key 查找 $total = 0; $s = microtime(true); $redis->keys("$key_pre:*"); $e = microtime(true); printf("1 000 000 key find cost %4f\n", $e-$s);