search
HomePHP FrameworkThinkPHPRedis cache configuration of thinkphp5

Redis cache configuration of thinkphp5

Jun 01, 2020 pm 05:24 PM
thinkphp

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',
        ],
    ],


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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!