/**
* 传不同的参数,实现不同的功能
* @param $key
* @param $value
* @param $time
*/
public function s($key,$value='',$time=null){
//传过来的参数是1个,那就是get方法
if(func_num_args() == 1){
//注意:这里不用$this->debug,是因为默认为true直接就进if然后return了,然后下面就不会执行了,所以他打印不出来
return $this->m->get($key); //【查】
//注意:加这也没效果,上面有return也是直接返回了。不知道老师是get方法中加debug是啥意思??
} else if(func_num_args() >= 2){
if($value === null){
$this->m->delete($key); //【删】
}else{
if($time === null){
$time = $this->time; //用属性中缓存的时间
}
$this->m->set($key,$value,$time); //【加】
return $this->debug(); //注意:这到无所谓,顶多上面执行完咯,有错误返回错误。但也要调用s方法得时候用echo输出下
}
}
}
private function debug(){
//开启调试模式才返回错误信息
if($this->debug){
if($this->m->getResultCode() != 0){
return $this->m->getResultMessage(); //直接返回错误信息
}
}
}
随便,实现的方式可能会不同,效果一样就行