tp5实现Redis的简单使用
生活随笔
收集整理的這篇文章主要介紹了
tp5实现Redis的简单使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
方法1:
Controller
<?php
namespace app\index\controller;use think\Controller;
use think\session\driver\Redis;class Index extends Controller
{public function index(){$redis = new Redis();if(!$redis->has('str')){var_dump($redis->set('str','this is redis_str'));}else{var_dump($redis->get('str'));}}
} ?
?
方法2:(前方雷區!!!)
config.php
// +----------------------------------------------------------------------// | 緩存設置// +----------------------------------------------------------------------'cache' => [// 驅動方式'type' => 'File',// 緩存保存目錄'path' => CACHE_PATH,// 緩存前綴'prefix' => '',//緩存有效期 0表示永久緩存'expire' => 0,],'redis' => [// 驅動方式'type' => 'redis',// 服務器地址'host' => '127.0.0.1', //redis服務器ip'port' => '6379','password'=> "",'timeout' => 86400],
Controller
<?php
namespace app\index\controller;use think\Cache;
use think\Controller;class Index extends Controller
{public function index(){if(!Cache::has('str')){var_dump(Cache::set('str','this is redis_str'));}else{var_dump(Cache::get('str'));}}
}? ?
轉載于:https://www.cnblogs.com/yulongcode/p/11240885.html
總結
以上是生活随笔為你收集整理的tp5实现Redis的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有知道这是啥电影的不,打僵尸的那种哟
- 下一篇: 混凝土一立方多少钱啊?