ThinkPHP5.1中使用redis缓存
2022-07-28 14:14:58
131
{{single.collect_count}}

ThinkPHP框架已经封装好redis驱动,不管是session还是cache都支持redis驱动,下面我们来了解一下在ThinkPHP5.1版本下如何使用redis缓存。

配置:/config/cache.phpreturn [

// 驱动方式

'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);

}

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}