Home > PHP Framework > ThinkPHP > body text

Using redis cache in ThinkPHP5.1

silencement
Release: 2020-01-30 22:43:08
forward
5102 people have browsed it

Using redis cache in ThinkPHP5.1

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

The above is the detailed content of Using redis cache in ThinkPHP5.1. 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