首页
IT
登录
6mi
u
盘
搜
搜 索
IT
简单的PHP redis 单例模式,(基本可以拿过去复制)
简单的PHP redis 单例模式,(基本可以拿过去复制)
xiaoxiao
2021-11-19
67
<?php
session_start
();
class
DB{
private static
$car
;
//私有静态变量;
private
$redis
;
//静态变量
private function
__construct(){
$this
->
redis
=
new
Redis();
$this
->
redis
->connect(
'127.0.0.1'
,
'6379'
);
}
private function
__clone(){
//防止克隆
}
public static function
test(){ //检测有没有实例化本身;
if
(!
self
::
$car
instanceof self
){
return
$car
=
new self
;
}
return self
::
$car
;
}
public function
tat(
$ar
){
}
}
$arr
=DB::
test
()->tat(
5
);
转载请注明原文地址: https://ju.6miu.com/read-678371.html
专利
最新回复
(
0
)