zoukankan      html  css  js  c++  java
  • tp框架利用redis存储session

    因tp每个版本不一致,只说大概流程:

    1.config文件中将sesion type改成redis

    'session' => [
      'id'  => '',
      // SESSION_ID的提交变量,解决flash上传跨域
      // 'var_session_id' => '',
      // SESSION 前缀
      'prefix'  => 'think',
      // 驱动方式 支持redis memcache memcached
      'type'  => 'redis',
      // 是否自动开启 SESSION
      'auto_start'     => true,
    ],

    2.config文件中增加redis连接信息

    'session_redis_config'  =>  [
        'host'         => '27.0.0.1', // redis主机
        'port'         => 6379, // redis端口
        'password'     => '', // 密码
        'select'       => 11, // 操作库
        'expire'       => 3600, // 有效期(秒)
        'timeout'      => 30, // 超时时间(秒)
        'persistent'   => true, // 是否长连接
        'session_name' => '', // sessionkey前缀
      ],

    3.redis session driver类文件引入config文件中的session_redis_config配置

      编辑thinkphp/library/think/session/driver/Redis.php

    protected $handler = null;
        //将$config属性赋值注释
        /*protected $config  = [
            'host'         => '127.0.0.1', // redis主机
            'port'         => 6379, // redis端口
            'password'     => '', // 密码
            'select'       => 11, // 操作库
            'expire'       => 3600, // 有效期(秒)
            'timeout'      => 30, // 超时时间(秒)
            'persistent'   => true, // 是否长连接
            'session_name' => '', // sessionkey前缀
        ];*/
    
        public function __construct($config = [])
        {
            //改变获取redis配置文件方式
            //$this->config = array_merge($this->config, $config);
            $this->config = array_merge(config('session_redis_config'), $config);
        }

    4.设置、获取session信息和之前一样无变化,test

    use thinkSession;
    Session::set("test", "TEST");
    Session::get('test');
  • 相关阅读:
    【读书笔记】之《把时间当做朋友》
    软件工程——五大模型
    VB中的GetUserName函数
    VB中 vbp vbw frm frx log bas 等扩展名大全
    【机房收费系统】——基本数据设定的理解
    在64位WindowsServer2012R2中安装Oracle10g第二版(10.2.0.4.0)-20160106
    Linux——vi命令详解
    使用Postman测试WebService接口
    npm和yarn的淘宝镜像添加
    yarn配置私有registry
  • 原文地址:https://www.cnblogs.com/shier-dong/p/14291222.html
Copyright © 2011-2022 走看看