Home  >  Article  >  PHP Framework  >  ThinkPHP5.1 uses redis cache

ThinkPHP5.1 uses redis cache

angryTom
angryTomforward
2019-10-14 12:35:237380browse

The ThinkPHP framework has encapsulated the redis driver. Both session and cache support the redis driver. Let's learn how to use redis cache under ThinkPHP5.1 version.

Configuration:/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',
    ],
    // 添加更多的缓存类型设置
];

Mainly look at redis

Assignment

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

Print

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

Recommended tutorial: thinkphp tutorial

The above is the detailed content of ThinkPHP5.1 uses redis cache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.liqingbo.cn. If there is any infringement, please contact admin@php.cn delete