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

ThinkPHP5.1 uses redis cache

angryTom
Release: 2019-10-14 12:35:23
forward
7443 people have browsed it

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

Mainly look at redis

Assignment

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

Print

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

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!

Related labels:
source:www.liqingbo.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template