$redis= Yii::$app -Redis;
$keys= ' Dll_mb_examine ';//defining key names
$list= $redis -Get($keys);//TakeKeyvalue
if(Empty($list)){
$data=examine::Getmobileexamine($userInfo[' UserId ']);
if(Empty($data)){
return$this -redirect(['/frontend/default/nomsg ',' msg '='No data currently',' title '='Approval Center']);
}
$redis -Set($keys,Serialize ($data));//Save Data
$redis -expire($keys,3600*5);//Cache Time5seconds
}
$data=unserialize ($list);
$spdata=config::GetConfig(' shenpileixing ');
foreach($data as$key=$val){
//update when editing the dataRedisCache
$key=yii::$app -params[' Cache_key '][' Cyj_info '].$data[' Earnestid '];
if(!Empty($key)){
Yii::$app -Cache -Delete($key);
}
Redis is introduced in the web.php file
' components '= [
' request '= [
//!!! Insert a secret key in the following (if it was empty)-this is required by cookie validation
' Cookievalidationkey '=' Pqwkcmqwadnwv2kqiepshk2xcyfailif ',
],
' Assetmanager '= [
' Linkassets '=true,
],
' Cache '= [
//' class ' = ' Yii\caching\filecache ',
' class '=' Yii\redis\cache ',
],
' Redis '= [
' class '=' Yii\redis\connection ',
' hostname '=' 192.168.0.227 ',
' Port '=6379,
' database '=0,
],
yiisoft/extensions.php Tail Append:
' Yiisoft/yii2-redis '=
Array(
' name '=' Yiisoft/yii2-redis ',
' Version '=' 2.2.0.0 ',
' Alias '=
Array(
' @yii/redis '=$vendorDir. '/yiisoft/yii2-redis ',
),
),
This article is from the "php/[email protected]" blog, be sure to keep this source http://liang3391.blog.51cto.com/178205/1883090
Yii2 Redis Use