thinkphp6 使用redis

磊落不羁 by:磊落不羁 分类:thinkphp6 时间:1年前 阅读:151 评论:0

1、cache.php 位于config文件夹下

<?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',
            'port' => '6379',
            'password' => '',
            'select' => '0',
            // 全局缓存有效期(0为永久有效)
            'expire' => 0,
            // 缓存前缀
            'prefix' => '',
            //默认缓存周期
            'timeout' => 3600,
        ],

    ],
];

2、使用中

$redis = new Redis(Config('cache.stores.redis'));
//设定数值
$redis->set('pasawu', 'test',30);
//获取数值
$pasa = $redis->get('pasawu');
非特殊说明,本文版权归原作者所有,转载请注明出处

本文地址:http://php.liulei.com.cn/?type=acticle&id=75

评论列表

发表评论

  • 昵称(必填)
  • 邮箱
  • 网址

TOP