首页 > 编程知识 正文

tp6入门,tp6性能

时间:2023-05-05 05:56:15 阅读:242482 作者:2815

一、redis的基础配置:

1、找到config配置文件下的cache.php

2、将redis配置代码加进去即可

<?php// +----------------------------------------------------------------------// | 缓存设置// +----------------------------------------------------------------------return [ // 默认缓存驱动 'default' => env('cache.driver', 'file'), // 缓存连接方式配置 'stores' => [ 'file' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, // 缓存标签前缀 'tag_prefix' => 'tag:', // 序列化机制 例如 ['serialize', 'unserialize'] 'serialize' => [], ], // redis缓存 'redis' => [ // 驱动方式 'type' => 'redis', // 服务器地址 'host' => '127.0.0.1', ], ],];

3、调用:

<?phpnamespace apppypcontroller;use thinkfacadeCache;class Ceshi{ public function index() { return '欢迎来到pyp世界'; } public function redisCeshi() { Cache::store('redis')->set('name','value',3600); return '操作成功'; }}

二、redis库的切换

1、在公共文件夹下 app/common (自建的,放哪儿按个人习惯)  新建Redis.php文件

2、键入代码

<?phpnamespace appcommon;use thinkfacadeCache;class Redis{ /** * redis 切库 * @param int $num 库号(0~15) */ public static function select($num=0) { Cache::store('redis')->handler()->select($num); }}

3、执行调用

<?phpnamespace apppypcontroller;use appcommonRedis;use thinkfacadeCache;class Ceshi{ public function index() { return '欢迎来到pyp世界'; } public function redisCeshi() { Redis::select(7); Cache::store('redis')->set('name8','chenxi',3600); $name8 = Cache::store('redis')->get('name8'); return $name8; }}

4、访问可返回值  chenxi

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。