-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.php
More file actions
82 lines (77 loc) · 1.89 KB
/
redis.php
File metadata and controls
82 lines (77 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/* (C)2006-2021 FoundPHP Framework.
* name: Database Object
* weburl: http://www.FoundPHP.com
* mail: master@FoundPHP.com
* author: 孟大川
* version: v3.201212
* start: 2006-05-24
* update: 2020-12-12
* payment: Free 免费
* This is not a freeware, use is subject to license terms.
* 此软件为授权使用软件,请参考软件协议。
* http://www.foundphp.com/?m=agreement
*/
Class Dirver_redis{
//连接数据库
function DBLink($dba=''){
if (class_exists('Redis')==false){
return 2;
}
$this->LinkID = new Redis();
$this->LinkID->connect($dba['dbhost'],($dba['dbport']!=''?$dba['dbport']:6379));
//设置库
if ((int)$dba['dbname']&& $dba['dbpass']==''){
@$this->LinkID->select((int)$dba['dbname']);
}
//设置密码
if ($dba['dbpass']){
$auth = $this->LinkID->auth(trim($dba['dbpass']));
if ($auth==false){
return 3;
}
}
return $this->LinkID;
}
//单条语句查询,默认先进先出
function query($name,$types='') {
switch($types){
case'lpop':
$result = $this->LinkID->lpop($name);
break;
default:
$result = $this->LinkID->rpop($name);
}
return $result;
}
//插入语句
function insert($name,$val='',$types='') {
switch($types){
case'rpush':
$result = $this->LinkID->rpush($name, $val);
break;
default:
$query = $this->LinkID->lpush($name, $val);
}
return array('query'=>$query);
}
//关闭当前数据库连接
function close(){
return $this->LinkID->close();
}
//获得版本
function version(){
$redis_ver = $this->LinkID->info();
ob_start();
ob_implicit_flush(0);
phpinfo();$php_info = ob_get_contents();
ob_end_clean();
foreach(explode("\n",$php_info) AS $k=>$v) {
if (strstr($v,'Redis Version')){
$verext = explode('Redis Version',strip_tags($v));
return 'PHP Redis:'.trim($verext[1]).', Redis Version:'.$redis_ver['redis_version'];
}
}
}
}
?>