search
HomeDatabaseRedisHow to use redis cache in tp6

How to use redis cache in tp6

May 27, 2023 pm 08:25 PM
redistp6

Install redis locally and configure phpredis extension

1. Download redis

Here you can download the redis software according to the number of bits in your system

How to use redis cache in tp6

2. Corresponding version php extension

Download the extension. Select the corresponding php version to download the corresponding one. The editor here uses php7.3.4nts
2.1 Will download the php_redis.dll and php_redis.pdb to the ext folder corresponding to the PHP version

How to use redis cache in tp6
How to use redis cache in tp6

##2.2 2. Find the php.ini file, open it, enter extension=php_redis and save it. Can

How to use redis cache in tp6
How to use redis cache in tp6

3. Configure environment variables

Right-click My Computer->Properties->Advanced System Settings Start Configuration

How to use redis cache in tp6
How to use redis cache in tp6

4. Open redis

Directly use the command Redis-server.exe to open

How to use redis cache in tp6

5.phpinfo() Check whether the phpredis extension is installed successfully

Use the method in the project to check
public function index()
{
    dump(phpinfo());
}

How to use redis cache in tp6

5.1 Open redis to create a new connection

How to use redis cache in tp6

How to use redis cache in tp6

6. Configure config/cache.php to add redis configuration

<?php

// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------

return [
    // 默认缓存驱动
    &#39;default&#39; => env(&#39;cache.driver&#39;, &#39;redis&#39;),

    // 缓存连接方式配置
    &#39;stores&#39;  => [
        &#39;file&#39; => [
            // 驱动方式
            &#39;type&#39;       => &#39;File&#39;,
            // 缓存保存目录
            &#39;path&#39;       => &#39;&#39;,
            // 缓存前缀
            &#39;prefix&#39;     => &#39;&#39;,
            // 缓存有效期 0表示永久缓存
            &#39;expire&#39;     => 0,
            // 缓存标签前缀
            &#39;tag_prefix&#39; => &#39;tag:&#39;,
            // 序列化机制 例如 [&#39;serialize&#39;, &#39;unserialize&#39;]
            &#39;serialize&#39;  => [],
        ],
        // 更多的缓存连接(配置成redis一样)
        &#39;redis&#39;=>[
            &#39;type&#39;       =>&#39;Redis&#39;,  // 这一句很重要
            &#39;host&#39;       => &#39;127.0.0.1&#39;,
            &#39;port&#39;       => 6379,
        ]
    ],
];

7. Use redis cache

<?php
namespace app\admin\controller;
use app\BaseController;
use think\cache\driver\Redis;
use think\facade\Cache;

class Index extends BaseController
{
    public function index()
    {
        Cache::store(&#39;redis&#39;)->set(&#39;phone&#39;, 150000266892);
        dump(Cache::store(&#39;redis&#39;)->get(&#39;phone&#39;));
    }
}

8. Check redis cache success

How to use redis cache in tp6

The above is the detailed content of How to use redis cache in tp6. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Redis vs databases: performance comparisonsRedis vs databases: performance comparisonsMay 14, 2025 am 12:11 AM

Redisoutperformstraditionaldatabasesinspeedforread/writeoperationsduetoitsin-memorynature,whiletraditionaldatabasesexcelincomplexqueriesanddataintegrity.1)Redisisidealforreal-timeanalyticsandcaching,offeringphenomenalperformance.2)Traditionaldatabase

When Should I Use Redis Instead of a Traditional Database?When Should I Use Redis Instead of a Traditional Database?May 13, 2025 pm 04:01 PM

UseRedisinsteadofatraditionaldatabasewhenyourapplicationrequiresspeedandreal-timedataprocessing,suchasforcaching,sessionmanagement,orreal-timeanalytics.Redisexcelsin:1)Caching,reducingloadonprimarydatabases;2)Sessionmanagement,simplifyingdatahandling

Redis: Beyond SQL - The NoSQL PerspectiveRedis: Beyond SQL - The NoSQL PerspectiveMay 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: A Comparison to Traditional Database ServersRedis: A Comparison to Traditional Database ServersMay 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

Redis: Introduction to a Powerful In-Memory Data StoreRedis: Introduction to a Powerful In-Memory Data StoreMay 06, 2025 am 12:08 AM

Redisisahigh-performancein-memorydatastructurestorethatexcelsinspeedandversatility.1)Itsupportsvariousdatastructureslikestrings,lists,andsets.2)Redisisanin-memorydatabasewithpersistenceoptions,ensuringfastperformanceanddatasafety.3)Itoffersatomicoper

Is Redis Primarily a Database?Is Redis Primarily a Database?May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Database, Server, or Something Else?Redis: Database, Server, or Something Else?May 04, 2025 am 12:08 AM

Redisisamultifacetedtoolthatservesasadatabase,server,andmore.Itfunctionsasanin-memorydatastructurestore,supportsvariousdatastructures,andcanbeusedasacache,messagebroker,sessionstorage,andfordistributedlocking.

Redis: Unveiling Its Purpose and Key ApplicationsRedis: Unveiling Its Purpose and Key ApplicationsMay 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

See all articles

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 Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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