diff --git a/configure b/configure
index 08e0e49..1ac243d 100755
--- a/configure
+++ b/configure
@@ -7,6 +7,21 @@
# USAGE
# ./configure -- configure local machine
# ./configure -c -- collect local configure files
+#
+# NOTE
+# check $PATH include
+# /usr/local/sbin
+# /usr/local/bin
+# /usr/sbin
+# /usr/bin
+# /sbin
+# /bin
+#
+# AUTHOR
+# Aborn Jiang (aborn.jiang@gmail.com)
+#
+# VERSION
+# v0.1 2014-03-04
###############################################################
ABSPATH=$(dirname $0)
cd ${ABSPATH}
diff --git a/phpd/create.php b/phpd/create.php
index c51f0fc..e2be87b 100644
--- a/phpd/create.php
+++ b/phpd/create.php
@@ -2,8 +2,8 @@
require_once('mysql2redis.php');
$items_number=2000000;
$tab_redis = new mysql2redis();
-$tab_redis->setTBname('bench');
$tab_redis->setDBname('test');
+$tab_redis->setTBname('bench');
$tab_redis->bench($items_number);
$tab_redis->bench($items_number, 'bench_no_index');
?>
diff --git a/phpd/dbops.php b/phpd/dbops.php
index 0afcac2..fd097e1 100644
--- a/phpd/dbops.php
+++ b/phpd/dbops.php
@@ -33,6 +33,11 @@ class dbops {
}
}
+ public function tabsize($sql)
+ {
+ return $this->mysqli->query($sql);
+ }
+
public function query($sql)
{
if ($this->connect()) {
diff --git a/phpd/iredis.php b/phpd/iredis.php
index 6da00d2..7d49d19 100644
--- a/phpd/iredis.php
+++ b/phpd/iredis.php
@@ -25,7 +25,8 @@ class iredis
public function __construct()
{
$this->redis = new redis();
- $this->redis->pconnect($this->redis_server, $this->redis_port);
+ $this->redis->connect($this->redis_server, $this->redis_port);
+ ## $this->redis->pconnect($this->redis_server, $this->redis_port);
}
public function __destruct()
@@ -58,6 +59,11 @@ class iredis
{
$this->redis->close();
}
+
+ public function select($database=0)
+ {
+ $this->redis->select($database);
+ }
public function append($key, $value)
{
diff --git a/phpd/looptest.php b/phpd/looptest.php
index 728c676..b713b66 100644
--- a/phpd/looptest.php
+++ b/phpd/looptest.php
@@ -29,9 +29,10 @@ class looptest
$ops = new dbops();
$ops->setTBname($tbname);
$ops->setDBname($dbname);
+ ##$start=$i*rand(1,950); # more then 2w
$start=$i*128;
- $conditions = sprintf("idx > %d and idx < %d;",
- $start, $start + 1000);
+ $conditions = sprintf ("idx > %d and idx < %d;",
+ $start, $start+1000);
$sql = sprintf("select * from %s where %s",
$tbname, $conditions);
$data = $ops->query($sql);
diff --git a/phpd/main.php b/phpd/main.php
index fe258e7..1f2b063 100644
--- a/phpd/main.php
+++ b/phpd/main.php
@@ -6,6 +6,7 @@
#require_once('mysql_info.php');
require_once('dbops.php');
+require_once('iredis.php');
echo "数据库测试页面\n
";
date_default_timezone_set('PRC');
@@ -60,10 +61,11 @@ echo "
";
echo "
";
echo "follow test redis:";
-$redis = new redis();
-$result = $redis->connect('127.0.0.1', 6379);
+$redis = new iredis();
+$result = $redis->configure('127.0.0.1', 6379);
#var_dump($result); //结果:bool(true)
-$redis->set('test', 'hello world!');
+#$redis->set('test', 'hello world!');
+#$redis->select(1);
echo $redis->get('test');
?>
diff --git a/phpd/mysql2redis.php b/phpd/mysql2redis.php
index ba04d85..d113258 100644
--- a/phpd/mysql2redis.php
+++ b/phpd/mysql2redis.php
@@ -24,7 +24,6 @@ class mysql2redis
public function __construct()
{
$this->iredis = new iredis();
-
$this->mysql = new dbops();
}
@@ -34,15 +33,23 @@ class mysql2redis
$this->mysql->close();
}
+ public function tabsize($tabname)
+ {
+ $sql = sprintf("select idx, count(idx) as total from %s", $tabname);
+ $rs=$this->mysql->tabsize($sql);
+ $no=$rs->fetch_row();
+ return $no[1];
+ }
+
public function bench($items_number, $bench='bench')
{ ## 测试前创建数据表格操作
-## $del_sql = sprintf("delete from %s where idx>0;", $bench);
+ ## $del_sql = sprintf("delete from %s where idx>0;", $bench);
$del_sql = sprintf("delete from %s;", $bench);
$this->mysql->query($del_sql);
-## $this->mysql->query("select * from bench;");
+ ## $this->mysql->query("select * from bench;");
for ($i=0; $i < $items_number; $i++)
{
- $value = sprintf("(%d,\"name%d\",\"%s\")", $i, $i, $bench);
+ $value = sprintf("(%d,%d,\"name%d\",\"%s\")", $i, $i+1, $i, $bench);
$insert_sql = sprintf("insert into %s values%s;",$bench,$value);
$this->mysql->query($insert_sql);
}
diff --git a/phpd/redis_action.php b/phpd/redis_action.php
index 3ceef3c..e2946b0 100644
--- a/phpd/redis_action.php
+++ b/phpd/redis_action.php
@@ -10,21 +10,26 @@ require_once('looptest.php');
#$tbname="account";
#$tbname="temp";
-$tbname="bench_no_index";
+#$tbname="bench_no_index";
#$tbname="bench";
$dbname="test";
-$loop_times=10;
-$items_number=30000;
+$loop_times=20;
$tab_redis = new mysql2redis();
$tab_redis->setTBname($tbname);
$tab_redis->setDBname($dbname);
# $tab_redis->bench($items_number, $tbname); ## 创建数据表格
-$sql = sprintf("select * from %s where idx > 29000 and idx < 30000", $tbname);
+$startI=9000; ## 29000
+$endI=10000; ## 30000
+$sql = sprintf("select * from %s where idx > %d and idx < %d", $tbname, $startI, $endI);
$tab_redis->mysql2redis($tbname, $sql);
######### 下面为测试调用
+echo "";
+echo $sql;
+echo "";
+
$lptest = new looptest();
$lptest->configure($tbname, $dbname);
@@ -41,13 +46,15 @@ echo "
"; echo "
";
echo "[redis对应表".$tbname." ]执行 $loop_times 次循环(单次时间 ms)为:";
echo ($rstime/$loop_times)*1000;
+$items_number = $tab_redis->tabsize($tbname);
+
echo "
"; echo "
";
echo "item=$items_number [数据库]/[redis]比值为:";
echo $dbtime/$rstime;
######### 下面为测试输出
-#$tab_redis->print_mysql_table();
+#$tab_redis->print_mysql_table($tbname);
# var_dump($data);
?>
diff --git a/sql/create.sql b/sql/create.sql
index 1281835..574d24f 100644
--- a/sql/create.sql
+++ b/sql/create.sql
@@ -4,16 +4,18 @@ DROP TABLE IF EXISTS bench_no_index;
CREATE TABLE bench (
idx INT(10) NOT NULL PRIMARY KEY,
+ age INT(10),
name VARCHAR(20) NOT NULL,
des VARCHAR(100) NOT NULL
);
-insert into bench value(0,'000','shanghai');
+insert into bench value(0,0,'000','shanghai');
CREATE TABLE bench_no_index (
idx INT(10) NOT NULL,
+ age INT(10),
name VARCHAR(20) NOT NULL,
des VARCHAR(100) NOT NULL
);
-insert into bench_no_index value(0,'000','shanghai');
+insert into bench_no_index value(0,0,'000','shanghai');