Thinkphp5怎么擴(kuò)展Redis數(shù)據(jù)庫(kù),實(shí)現(xiàn)Redis的CURD操作
Redis怎么使用Redis數(shù)據(jù)庫(kù)歌懒,本篇文章主要介紹在Thinkphp5項(xiàng)目中如何使用Redis數(shù)據(jù)庫(kù)
一躲庄、基礎(chǔ)環(huán)境
PHP擴(kuò)展:?http://www.zhaisui.com/article/38.html
二、數(shù)據(jù)庫(kù)配置
1济丘、頭部引用Redis類
use think\cache\Driver;
2近哟、Redis 數(shù)據(jù)庫(kù)配置信息
$config = [
'host'? ? ? => '服務(wù)器IP地址',
'port'? ? ? => Redis端口號(hào),
'password'? => 'Redis訪問密碼',
'select'? ? => 0,
'timeout'? ? => 0,
'expire'? ? => 0,
'persistent' => false,
'prefix'? ? => '',
];
三、 Redis基本使用
$Redis=new Redis($config);
$Redis->set("test","test");
echo $Redis->get("test");
四荠列、具體代碼如下:
namespace app\index\controller;
use? \think\Db;
use think\cache\driver\Redis;
class Index
{
public function index()
{
$config = [
'host'? ? ? => '服務(wù)器IP地址',
'port'? ? ? => Redis端口號(hào),
'password'? => 'Redis訪問密碼',
'select'? ? => 0,
'timeout'? ? => 0,
'expire'? ? => 0,
'persistent' => false,
'prefix'? ? => '',
];
$Redis=new Redis($config);
$Redis->set("test","test");
echo? $Redis->get("test");
}
}