如何实现ThinkPHP5.1中的Redis缓存功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计323个文字,预计阅读时间需要2分钟。
ThinkPHP框架已完美封装Redis驱动,支持session和cache等均可用redis驱动。以下是在ThinkPHP5.1版本下使用Redis缓存的具体步骤:
配置:/config/cache.phpphpreturn [ // 驱动方式 'type'=> 'Redis', // Redis配置 'options'=> [ // Redis服务器地址 'host'=> '127.0.0.1', // Redis端口 'port'=> 6379, // Redis数据库索引 'database'=> 0, // 选择持久化方式 'persistent'=> false, // 是否使用连接池 'pool'=> false, ],];
ThinkPHP框架已经封装好redis驱动,不管是session还是cache都支持redis驱动,下面我们来了解一下在ThinkPHP5.1版本下如何使用redis缓存。
配置:/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', ], // 添加更多的缓存类型设置 ];
主要是看redis这一块
赋值
public function redis(){ Cache::store('redis')->set('name','value'); }
打印
public function redisShow(){ $name = Cache::store('redis')->get('name'); print_r($name); }
以上就是ThinkPHP5.1中使用redis缓存的详细内容,更多请关注自由互联其它相关文章!
本文共计323个文字,预计阅读时间需要2分钟。
ThinkPHP框架已完美封装Redis驱动,支持session和cache等均可用redis驱动。以下是在ThinkPHP5.1版本下使用Redis缓存的具体步骤:
配置:/config/cache.phpphpreturn [ // 驱动方式 'type'=> 'Redis', // Redis配置 'options'=> [ // Redis服务器地址 'host'=> '127.0.0.1', // Redis端口 'port'=> 6379, // Redis数据库索引 'database'=> 0, // 选择持久化方式 'persistent'=> false, // 是否使用连接池 'pool'=> false, ],];
ThinkPHP框架已经封装好redis驱动,不管是session还是cache都支持redis驱动,下面我们来了解一下在ThinkPHP5.1版本下如何使用redis缓存。
配置:/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', ], // 添加更多的缓存类型设置 ];
主要是看redis这一块
赋值
public function redis(){ Cache::store('redis')->set('name','value'); }
打印
public function redisShow(){ $name = Cache::store('redis')->get('name'); print_r($name); }
以上就是ThinkPHP5.1中使用redis缓存的详细内容,更多请关注自由互联其它相关文章!

