首页 > 代码库 > yii2 redis使用
yii2 redis使用
$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‘,
),
),
本文出自 “PHP/Linux@HeFei” 博客,请务必保留此出处http://liang3391.blog.51cto.com/178205/1883090
yii2 redis使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。