Home>Article>PHP Framework> Let’s talk about how to use Redis in ThinkPHP6

Let’s talk about how to use Redis in ThinkPHP6

青灯夜游
青灯夜游 forward
2022-08-18 11:41:01 2549browse

How to use Redis in ThinkPHP6? The following article will introduce how to use Redis in ThinkPHP6. I hope it will be helpful to everyone!

Let’s talk about how to use Redis in ThinkPHP6

My running environment: CentOS 8.2 Pagoda

If the environment is different, please install Redis and php extensions according to your own environment

First install Redis in Pagoda [Software Store], and then install the Redis extension in the corresponding PHP version management

1. Set the Redis parameter configuration in the TP6 project

config/cache.php

 Env::get('cache.driver', 'file'), // 缓存连接方式配置 'stores' => [ 'file' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, // 缓存标签前缀 'tag_prefix' => 'tag:', // 序列化机制 例如 ['serialize', 'unserialize'] 'serialize' => [], ], //新增redis 'redis' => [ // 驱动方式 'type' => 'redis', // 服务器地址 'host' => '127.0.0.1', 'password' => '',//如果没有设置密码为空 ], // 更多的缓存连接 ], ];

2. Using Redis

2a511e1eaeae82692a6b6a9e7fb908aeset('pasawu', 'test'); $pasa = $redis->get('pasawu'); dd($pasa); } }

[Related tutorial recommendations:thinkphp framework]

The above is the detailed content of Let’s talk about how to use Redis in ThinkPHP6. For more information, please follow other related articles on the PHP Chinese website!

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