<? 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 ], ];
<? 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); } }