您好,欢迎来到尚车旅游网。
搜索
您的当前位置:首页ThinkPHP5.1中使用redis缓存

ThinkPHP5.1中使用redis缓存

来源:尚车旅游网

ThinkPHP框架已经封装好redis驱动,不管是session还是cache都支持redis驱动,下面我们来了解一下在ThinkPHP5.1版本下如何使用redis缓存。

配置:/config/cache.php

return [
 // 驱动方式
 'type' => 'File',
 // 缓存保存目录
 'path' => '',
 // 缓存前缀
 'prefix' => '',
 // 缓存有效期 0表示永久缓存
 'expire' => 0,
 'default' => [
 'type' => 'file',
 // 全局缓存有效期(0为永久有效)
 'expire'=> 0,
 // 缓存前缀
 'prefix'=> 'think',
 // 缓存目录
 'path' => '../runtime/cache/',
 ],
 'redis' => [
 'type' => 'redis',
 'host' => '127.0.0.1',
 // 全局缓存有效期(0为永久有效)
 'expire'=> 0,
 // 缓存前缀
 'prefix'=> 'think',
 ],
 // 添加更多的缓存类型设置
];

主要是看redis这一块

赋值

public function redis(){
 Cache::store('redis')->set('name','value');
}

打印

public function redisShow(){
 $name = Cache::store('redis')->get('name');
 print_r($name);
}

Copyright © 2019- sceh.cn 版权所有 湘ICP备2023017654号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务