redis->executeCommand('HGETALL', [$cacheKey]); if(!empty($user)){ $arr = []; $i = 0; $x = 0; foreach($user as $key => $val){ $i++; if($i%2 == 0){ $arr[$x]['value'] = $val; $x++; }else{ $arr[$x]['key'] = $val; } } $userArr = []; foreach($arr as $key => $val){ $userArr[$val['key']] = $val['value']; } return $userArr; } $user = xhUnionUser::find()->where(['unionId' => $unionId])->asArray()->one(); if(empty($user)){ return []; } $params = [$cacheKey]; foreach($user as $key => $val){ $params[] = $key; $params[] = $val; } Yii::$app->redis->executeCommand('HMSET',$params);//将用户信息、用户标签放入缓存 return $user; } public static function refreshById($unionId) { $cacheKey = configDict::getCacheKey('xhUnionUser').$unionId; Yii::$app->redis->executeCommand('DEL', [$cacheKey]); return self::getById($unionId); } public static function updateById($unionId,$data) { xhUnionUser::updateByCondition(['unionId' => $unionId], $data); $userKey = configDict::getCacheKey('xhUnionUser').$unionId; $userParams = [$userKey]; foreach($data as $key => $val){ $userParams[] = $key; $userParams[] = $val; } Yii::$app->redis->executeCommand('HMSET',$userParams);//更新缓存信息 } }