$redis = Yii::$app->redis;$keys = ‘dll_mb_examine‘;//定义键名$list = $redis->get($keys);//取key值if(empty($list)){ $data=Examine::getMobileExamine($userInfo[‘userId‘]); if(empty($data)){ return $this->redirect([‘/frontend/default/nomsg‘,‘msg‘=>‘暂无数据‘,‘title‘=>‘审批中心‘]); } $redis->set($keys,serialize($data));//存数据 $redis->expire($keys,3600*5);//缓存时间5秒}
$data=unserialize($list);$spdata=Config::getConfig(‘shenpileixing‘);foreach($data as $key=>$val){
//编辑数据的时候更新redis缓存$key=Yii::$app->params[‘cache_key‘][‘cyj_info‘].$data[‘earnestId‘];if(!empty($key)){ Yii::$app->cache->delete($key);}
web.php文件里引入redis
‘components‘ => [ ‘request‘ => [ // !!! insert a secret key in the following (if it is 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 尾部追加:
‘yiisoft/yii2-redis‘ => array ( ‘name‘ => ‘yiisoft/yii2-redis‘, ‘version‘ => ‘2.2.0.0‘, ‘alias‘ => array ( ‘@yii/redis‘ => $vendorDir . ‘/yiisoft/yii2-redis‘, ), ),
时间: 2024-11-07 00:07:52