Home > PHP Framework > ThinkPHP > Redis cache configuration of thinkphp5

Redis cache configuration of thinkphp5

L
Release: 2020-06-01 17:24:53
forward
5299 people have browsed it

Redis cache configuration of thinkphp5

thinkphp5’s Redis cache configuration

thinkphp uses the cache class to provide cache function support and adopts a driver method , initialization is required before using the cache. Supported cache types include file, memcache, wincache, sqlite, redis and xcache, etc. The default is file type. To configure redis cache, you can configure redis alone or use multiple cache types at the same time. The configuration methods are as follows:

thinkphp uses the cache class to provide cache function support and adopts the driver method. Initialization is required before using the cache. Supported cache types include file, memcache, wincache, sqlite, redis and xcache, etc. The default is file type. To configure redis cache, you can configure redis alone or use multiple cache types at the same time. The configuration methods are as follows:

1. Configure only the redis cache, and modify the cache settings in the configuration file (app/config.php) as follows:

2. Configure multiple cache types, use the Cache type, the configuration method is as follows:

 'cache' =>  [
        // 使用复合缓存类型
        'type'  =>  'complex',
        // 默认使用的缓存
        'default'   =>  [
            // 驱动方式
            'type'   => 'File',
            // 缓存保存目录
            'path'   => CACHE_PATH,
        ],
        // 文件缓存
        'file'   =>  [
            // 驱动方式
            'type'   => 'file',
            // 设置不同的缓存保存目录
            'path'   => RUNTIME_PATH . 'file/',
        ],
        // redis缓存
        'redis'   =>  [
            // 驱动方式
            'type'   => 'redis',
            // 服务器地址
            'host'       => '192.168.1.100',
        ],
    ],
Copy after login


When using the cache type, you need to use the store method to switch the cache as needed.

When using

Cache::set('name', 'value');
Cache::get('name');
, The cache configuration with the default cache ID is used. If you need to switch to other cache identification operations, you can use:

// Switch to file operation
Cache::store('file')->set('name','value') ;
Cache::get('name');
// Switch to redis operation
Cache::store('redis')->set('name','value');
Cache::get('name');
For example, when querying an article, first query it from redis. If the information is not found, the result will be retrieved from the database and stored in redis.

Redis cache configuration of thinkphp5

Recommended tutorial: "TP5"

The above is the detailed content of Redis cache configuration of thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template