<?php
class MySessionHandler implements SessionHandlerInterface
{
private $redis;
private $sessionsavepath;
private $sessionname;
public function __construct()
{
$this->redis = new Redis();
$this->redis->connect('127.0.0.1',6379);
}
public function close()
{
return true;
}
public function destroy($session_id)
{
if($this->redis->delete($session_id)){
return true;
}
return false;
}
public function gc($maxlifetime)
{
return true;
}
public function open($sessionsavepath, $name)
{
return true;
}
public function read($session_id)
{
if($value = $this->redis->get($session_id)){
return $value;
}else{
return false;
}
}
public function write($session_id, $session_data)
{
if($this->redis->set($session_id,$session_data,60)){
return true;
}else{
return false;
}
}
}
$handler = new MySessionHandler();
session_set_save_handler($handler, true);
session_start();
//$_SESSION['sess_name'] = 'xd';
var_dump($_SESSION);
action
本站未注明转载的文章均为原创,并采用
CC BY-NC-SA 4.0授权协议,
转载请注明来源,谢谢!如本站内容对你有所帮助的话,欢迎订阅关注
邢栋博客,唠嗑(分享)每日的折腾经历。
已有 0 条评论