tp5实现Redis的简单使用
生活随笔
收集整理的這篇文章主要介紹了
tp5实现Redis的简单使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方法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:(前方雷區(qū)!!!)
config.php
// +----------------------------------------------------------------------// | 緩存設(shè)置// +----------------------------------------------------------------------'cache' => [// 驅(qū)動(dòng)方式'type' => 'File',// 緩存保存目錄'path' => CACHE_PATH,// 緩存前綴'prefix' => '',//緩存有效期 0表示永久緩存'expire' => 0,],'redis' => [// 驅(qū)動(dòng)方式'type' => 'redis',// 服務(wù)器地址'host' => '127.0.0.1', //redis服務(wù)器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'));}}
}? ?
轉(zhuǎn)載于:https://www.cnblogs.com/yulongcode/p/11240885.html
總結(jié)
以上是生活随笔為你收集整理的tp5实现Redis的简单使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 有知道这是啥电影的不,打僵尸的那种哟
- 下一篇: 自己开发开源jquery插件--给jqu