Home >PHP Framework >ThinkPHP >ThinkPHP5.1 uses redis cache
The ThinkPHP framework has encapsulated the redis driver. Both session and cache support the redis driver. Let's learn how to use redis cache under ThinkPHP5.1 version.
Configuration:/config/cache.php
return [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, 'default' => [ 'type' => 'file', // 全局缓存有效期(0为永久有效) 'expire'=> 0, // 缓存前缀 'prefix'=> 'think', // 缓存目录 'path' => '../runtime/cache/', ], 'redis' => [ 'type' => 'redis', 'host' => '127.0.0.1', // 全局缓存有效期(0为永久有效) 'expire'=> 0, // 缓存前缀 'prefix'=> 'think', ], // 添加更多的缓存类型设置 ];
Mainly look at redis
Assignment
public function redis(){ Cache::store('redis')->set('name','value'); }
public function redisShow(){ $name = Cache::store('redis')->get('name'); print_r($name); }
Recommended tutorial: thinkphp tutorial
The above is the detailed content of ThinkPHP5.1 uses redis cache. For more information, please follow other related articles on the PHP Chinese website!