Welcome
We've been working hard

How to use Redis in ThinkPaRP6

How to use Redis in ThinkPaRP6? Today, I saw an article on the Internet about how to use Redis, which I feel is good. I will share it with you today. I hope it can help everyone.

My server is CentOS 8.2, and then the pagoda panel is installed. If the environment is different, you need to install Redis and php extensions according to your environment

I first install Redis in the pagoda [software store], and then install Redis extensions in the corresponding php version management

1. Set Redis parameter configuration in TP6 project

File path: config/cache.php

 <? php use think\facade\Env; // +---------------------------------------------------------------------- //| Cache Settings // +---------------------------------------------------------------------- return [ //Default Cache Driver 'default' => Env::get('cache.driver', 'file'), //Cache connection mode configuration 'stores'  => [ 'file'  => [ //Drive mode 'type'       => 'File', //Cache save directory 'path'       => '', //Cache prefix 'prefix'     => '', //Cache validity period 0 indicates permanent cache 'expire'     => 0, //Cache label prefix 'tag_prefix' => 'tag:', //Serialization mechanism such as ['serialize ',' unserialize '] 'serialize'  => [], ], //New Redis 'redis' => [ //Drive mode 'type'     => 'redis', //Server address 'host'     => '127.0.0.1', 'password'=>'',//If the password is not set, it is empty ], //More cache connections ], ];

2. Use Redis

 <? php namespace app\api\controller; use think\cache\driver\Redis; use think\facade\Config; class Test { public function test() { $redis = new Redis(Config::get('cache.stores.redis')); $redis->set('pasawu', 'test'); $pasa = $redis->get('pasawu'); dd($pasa); } }

 

Like( zero ) Reward
Do not reprint without permission: New Start Blog » How to use Redis in ThinkPaRP6


Follow the public account "New Start Software Steward"

Get the latest network resources and cracking software!
Play with all kinds of software

comment Grab the sofa

You must log in before commenting!

 

Reward the author of the article if you think it is useful

Thank you very much for your reward, we will continue to give more high-quality content, let's create a better online world together!

Scan Alipay and reward

Scan WeChat and reward