参数参考位置:thinkphp\library\think\cache\driver

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几个方法

thinkphp5 redis使用的更多相关文章

  1. ThinkPHP5+Redis单例型购物车

    <?php /** * Redis + 单例型购物车 * param $basket 存储商品信息 * param $ins 存储实例化对象 */ namespace lib; use redi ...

  2. ThinkPHP5.0中Redis的使用和封装(原创)

    Redis是一种常用的非关系型数据库,主要用作数据缓存,数据保存形式为key-value,键值相互映射.它的数据存储跟MySQL不同,它数据存储在内存之中,所以数据读取相对而言很快,用来做高并发非常不 ...

  3. redis+thinkphp5的注册、登陆、关注基础例子

    最近初步接触redis,结合thinkphp5与redis,写了一个用户注册的基础例子,用于学习. 这个例子是结合了兄弟连的redis视频,最后两节的内容写的:https://study.163.co ...

  4. thinkphp5使用redis

    1.设置应用配置文件config.php type可以是很多分类File.Redis等等 2.thinkphp5使用redis新建application/index/controller/index. ...

  5. thinkphp5.0上对redis的具体操作

    一.环境搭建 首先先安装composer.thinkphp5.0版本.和redis的windows版本的redis程序或者linux版本的redis程序,linux安装教程: https://www. ...

  6. 扩展thinkphp5的redis类方法

    笔者在开发时发现,thinkphp5的自带redis类方法,只有简单的读取缓存.写入缓存的基本方法,远不能满足我们业务的需求.redis本身支持五种数据类型,string(字符串).hash(哈希). ...

  7. thinkphp5选择redis库,让数据存入不同的redis库

    thinkphp5选择redis库,让数据存入不同的redis库 在登录的时候把个人信息存入redis,选择redis库1号库, db1 读取redis里面的个人信息

  8. thinkphp5使用redis实现秒杀商品活动

    如题,废话少说贴码为上↓ // 初始化redis数据列表 模拟库存50,redis搭建在centos中已开启 public function redisinit(){ $store=50; // 库存 ...

  9. thinkphp5简单使用redis缓存

    <?php namespace app\index\controller; use think\Controller; use think\Cache\Driver\Redis; class I ...

随机推荐

  1. OJ测试数据追溯方法

    https://blog.csdn.net/iwts_24/article/details/79240987 我是从这个博客知道还有从比赛官方网站扒测试数据的方法,但是下面的链接有些是失效的. 所以我 ...

  2. Android -ui控件

    一:TextView控件 TextView --> View 1.创建TextView的两种方式: 1.1编写TextView类 TextView tv = new TextView(this) ...

  3. Python入门习题6.猜数游戏和其异常处理

    例6:在程序中预设一个0~9之间的整数,让用户通过键盘输入所猜的数,如果大于预设的数,显示“遗憾,太大了”:小于预设的数,显示“遗憾,太小了”,如此循环,直至猜中数,显示”预测N次,猜中了”,其中N是 ...

  4. python自定义迭代器对象以及可迭代对象

    # coding=utf8 from collections import Iterator from collections import Iterable #迭代器对象 class OwnIter ...

  5. Pandas的高级操作

    pandas数据处理 1. 删除重复元素 使用duplicated()函数检测重复的行,返回元素为布尔类型的Series对象,每个元素对应一行,如果该行不是第一次出现,则元素为True keep参数: ...

  6. 并行开发 8.用VS性能向导解剖你的程序

    原文:8天玩转并行开发——第八天 用VS性能向导解剖你的程序 最后一篇,我们来说说vs的“性能向导",通常我们调试程序的性能一般会使用Stopwatch,如果希望更加系统的了解程序,我们就需 ...

  7. JSTL 使用 c:forEach 累加变量值

    <body> <%    int x = 1;    int y = 2;    request.setAttribute("x", x);    request ...

  8. unity ui坐标系转换

    世界坐标: transform.position获取的是世界坐标 屏幕坐标: 单位像素 屏幕左下角(0,0)右上角(Screen.width,Screen.height) Screen.width = ...

  9. Error- spark streaming 打包将全部依赖打进去Invalid signature file digest for Manifest main attributes

    spark streaming 打包将全部依赖打进去,运行jar包报错:如下 Exception in thread "main" java.lang.SecurityExcept ...

  10. Android学习电子书