Yii2 Redis Use

Source: Internet
Author: User


$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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.