• TP5中用redis缓存


    在config.php配置文件下找到缓存设置,将原来的文件缓存修改为redis缓存,也可以改为多种类型的缓存:

        // +----------------------------------------------------------------------
        // | 缓存设置
        // +----------------------------------------------------------------------
    
    
    /*    'cache'                  => [
            // 驱动方式
            'type'   => 'File',
            // 缓存保存目录
            'path'   => CACHE_PATH,
            // 缓存前缀
            'prefix' => '',
            // 缓存有效期 0表示永久缓存
            'expire' => 0,
        ],*/
    
        'cache' => [
            // 使用复合缓存类型
            'type' => 'complex',
            // 默认使用的缓存
            'default' => [
                // 驱动方式
                'type' => 'File',
                // 缓存保存目录
                'path' => CACHE_PATH,
            ],
            // 文件缓存
            'file' => [
                // 驱动方式
                'type' => 'file',
                // 设置不同的缓存保存目录
                'path' => RUNTIME_PATH . 'file/',
            ],
            // redis缓存
            'redis' => [
                // 驱动方式
                'type' => 'redis',
                // 服务器地址
                'host' => '127.0.0.1', // 本地环境先开启redis服务端 redis-service.exe
                'port' => '6379',
            ],
        ],

    这样就可以使用redis来缓存数据了。用法如下:

    	hinkCache::store('redis')->handler()->hMSet('test', array('k1'=>123));

    其实就是因为  hinkCache::store('redis')->handler()  这一步返回是redis实例化对象,所以通过这个对象可以操作其他redis数据结构方法

        /**
         * 返回句柄对象,可执行其它高级方法
         *
         * @access public
         * @return object
         */
        public function handler()
        {
            return $this->handler;
        }

    注意: 不过在window下测试redis, 还要开启它服务端才行 redis-service.exe

  • 相关阅读:
    基于HttpListener的web服务器
    基于TcpListener的web服务器
    一个简单的web服务器
    c# 6.0新特性(二)
    c# 6.0新特性(一)
    c#之Redis实践list,hashtable
    html5摇一摇[转]
    在Microsoft-IIS/10.0上面部署mvc站点的时候,出现404的错误
    [实战]MVC5+EF6+MySql企业网盘实战(28)——其他列表
    让DELPHI自带的richedit控件显示图片
  • 原文地址:https://www.cnblogs.com/pyspang/p/11185759.html
Copyright © 2020-2023  润新知