首先在Thinkphp 配置项里面设置
'SESSION_OPTIONS'=>array( "session.save_handler"=>"redis", "session.save_path"=>"tcp://localhost:6379"//redis主服务器 ),测试:
public function session_test(){ session_start(); header("Content-type:text/html;charset=utf-8"); if(isset($_SESSION['test'])){ $_SESSION['test'] = $_SESSION['test'] + 1; }else{ $_SESSION['test'] = 1; } print_r($_SESSION); print_r(session_id()); }
public function session_test2(){ ini_set("session.save_handler", "redis"); ini_set("session.save_path", "tcp://localhost:6380");//redis从服务器 session_start(); print_r($_SESSION); print_r(session_id()); }