phpRedisAdmin :github地址 图形化管理界面
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin
git clone https://github.com/nrk/predis.git vendor
首先安装上述的Redis图形化管理界面,能够方便的管理Redis数据
为了降低Mysql的并发数,先把用户的微博存在Redis中
假设用户发布的时候需要三个字段,uid(用户ID号),username(用户姓名),content(‘用户的评论‘)
比如用户传递以下信息
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$redis = new Redis();
$redis ->connect( ‘127.0.0.1‘ , 6379);
$web_info = array (
‘uid‘ => ‘123456‘ ,
‘username‘ => ‘123‘ ,
‘content‘ => ‘123‘
);
$list = json_encode( $web_info );
$redis ->lpush( ‘weibo_lists‘ , $list );
$redis ->close();
var_dump( $list );
?>
|
此处可以看到我们的redis已经有数据了
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
class qq{
public function post( $uid = ‘‘ , $username = ‘‘ , $content = ‘‘ ){
try {
$dsn = "mysql:host;dbname=localhost;dbname=test" ;
$db = new PDO( $dsn , ‘root‘ , ‘root‘ );
$db -> exec ( "SET NAMES UTF8" );
$sql = "insert into test(uid,username,content)values(‘$uid‘,‘$username‘,‘$content‘)" ;
$db -> exec ( $sql );
} catch (PDOException $e ){
$e ->getMessage();
}
}
}
|
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
include "data.php" ;
$qq = new qq();
$redis = new Redis();
$redis ->connect( ‘127.0.0.1‘ , 6379);
if ( $redis -> lsize( ‘weibo_lists‘ )){
$info = $redis ->rpop( ‘weibo_lists‘ );
$info = json_decode( $info );
$qq ->post( $info ->uid, $info ->username, $info ->content);
}
$redis ->close();
var_dump( $info );
?>
|
我们能看到数据库已经有数据了