• thinkphp5 redis使用


    参数参考位置:thinkphplibrary hinkcachedriver

    class Redis extends Driver
    {
        protected $options = [
            'host'       => '127.0.0.1',
            'port'       => 6379,
            'password'   => '',
            'select'     => 0,
            'timeout'    => 0,
            'expire'     => 0,
            'persistent' => false,
            'prefix'     => '',
        ];

    方式一:控制器

    public function index(){
            $config = [
                'host' => '192.168.70.161',
                'port' => 6379,
                'password' => 'admin999',
                'select' => 0,
                'timeout' => 0,
                'expire' => 0,
                'persistent' => false,
                'prefix' => '',
            ];
     
            $Redis=new Redis($config);
            $Redis->set("test","test");
            echo $Redis->get("test");
        }

    方式二:符合类型缓存(配置文件)

    config.php

      'cache'                  => [
            // 使用复合缓存类型
            'type'  =>  'complex',
            // 默认使用的缓存
            'default'   =>  [
                // 驱动方式
                'type'   => 'redis',
                // 缓存保存目录
                'path'   => CACHE_PATH,
            // 文件缓存
                ],
            'file'   =>  [
                // 驱动方式
                'type'   => 'file',
                // 设置不同的缓存保存目录
                'path'   => CACHE_PATH,
            ],
    //        // 驱动方式
    
            // redis缓存
            'redis'   =>  [
                // 驱动方式
                'type'   => 'redis',
                // 服务器地址
                'host'  => '192.168.70.161',
                'expire' => 0,
                'port' => 6379,
                'password'=>'hello',
                'select'=>14 //选择几号库
                
    
            ],
    Cache::store('redis')->set('name','999');
    Cache::store('file')->set('name1','999');

    链接方式三:配置文件

    //redis连接
                $redis = new Redis();
                $redis->connect('192.168.70.161','6379');
                $redis->auth('hello');
                $redis->select(14);
           $redis->Lrange('runoobkey','0','10') 

    // thinkphp 默认不能使用redis的push、lLen等操作,需要连接自带的redis.php

    方式一和方式二连接都无法使用redis自带的push,lLen,Lrange方法,只能使用thinkphp自带的redis几个方法

  • 相关阅读:
    影响一个UIView是否能正常显示的几个因素
    浅谈多进程多线程的选择
    Spring阅读方法
    数据库范式通俗解释
    MySQL学习笔记(二):MySQL数据类型汇总及选择参考
    MySQL学习笔记(一):SQL基础
    存储过程优缺点
    MySQL学习笔记(三):常用函数
    bzoj 3576[Hnoi2014]江南乐 sg函数+分块预处理
    bzoj 3166 [Heoi2013]Alo 可持久化Trie
  • 原文地址:https://www.cnblogs.com/yehuisir/p/11689338.html
Copyright © 2020-2023  润新知