Home  >  Article  >  PHP Framework  >  Using redis cache in ThinkPHP5.1

Using redis cache in ThinkPHP5.1

silencement
silencementforward
2020-01-30 22:43:085104browse

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

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);
}

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!

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