很奇怪,php 引入了phar,但是报错,说PredisClient类找不到?
程序员文章站
2024-02-06 09:22:04
...
redis) {
$cfg = [
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379
];
$this->redis = new \Predis\Client($cfg);
}
}
/**
* Close the session
* @since 5.4.0
*/
public function close()
{
$this->redis->quit();
return true;
}
/**
* Destroy a session
* @since 5.4.0
*/
public function destroy($session_id)
{
$this->connect();
return $this->redis->del($session_id);
}
/**
* Cleanup old sessions
* @since 5.4.0
*/
public function gc($maxlifetime)
{
return true;
}
/**
* Initialize session
* @since 5.4.0
*/
public function open($save_path, $session_id)
{
return true;
}
/**
* Read session data
* @since 5.4.0
*/
public function read($session_id)
{
$this->connect();
$data = $this->redis->get($session_id);
return $data;
}
/**
* Write session data
* @since 5.4.0
*/
public function write($session_id, $session_data)
{
$this->connect();
$expire = configure('Ymf.Account.expire');
if(is_int($expire) && $expire > 0) {
$result = $this->redis->setex($session_id, $expire, $session_data);
$re = $result ? 'true' : 'false';
}else{
$result = $this->redis->set($session_id, $session_data);
$re = $result ? 'true' : 'false';
}
var_dump($result);
return $re;
}
}
session_set_save_handler(new MySession());
session_start();
$_SESSION['name'] = 43;
这是目录
回复内容:
redis) {
$cfg = [
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379
];
$this->redis = new \Predis\Client($cfg);
}
}
/**
* Close the session
* @since 5.4.0
*/
public function close()
{
$this->redis->quit();
return true;
}
/**
* Destroy a session
* @since 5.4.0
*/
public function destroy($session_id)
{
$this->connect();
return $this->redis->del($session_id);
}
/**
* Cleanup old sessions
* @since 5.4.0
*/
public function gc($maxlifetime)
{
return true;
}
/**
* Initialize session
* @since 5.4.0
*/
public function open($save_path, $session_id)
{
return true;
}
/**
* Read session data
* @since 5.4.0
*/
public function read($session_id)
{
$this->connect();
$data = $this->redis->get($session_id);
return $data;
}
/**
* Write session data
* @since 5.4.0
*/
public function write($session_id, $session_data)
{
$this->connect();
$expire = configure('Ymf.Account.expire');
if(is_int($expire) && $expire > 0) {
$result = $this->redis->setex($session_id, $expire, $session_data);
$re = $result ? 'true' : 'false';
}else{
$result = $this->redis->set($session_id, $session_data);
$re = $result ? 'true' : 'false';
}
var_dump($result);
return $re;
}
}
session_set_save_handler(new MySession());
session_start();
$_SESSION['name'] = 43;
这是目录
use 是使用命名空间的意思
use Predis\Client;
使用Predis空间下的 client 类
use \Predis\Client;
或者即然下面使用时用的完整命名空间,直接把use去掉
上一篇: Discuz!跨站大全_PHP教程
下一篇: 想请教一个问题啊。