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']; } unset($userArr['info_already_get_by_sql']); return $userArr; } $user = xhUserUnite::find()->where(['alipayId' => $alipayId,'sjId'=>$sjId])->asArray()->one(); $params = [$cacheKey]; $params[] = 'info_already_get_by_sql'; $params[] = 'ok';//redis没有办法设置带空值的键,加此可以数据空时表示取过 if(!empty($user)){ foreach($user as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); return $user; } public static function add($data) { $return = xhUserUnite::add($data); $sjId = $return['sjId']; $alipayId = $return['alipayId']; $cacheKey = dict::getCacheKey('xhUserUnite').'_'.$sjId.'_'.$alipayId; $params = [$cacheKey]; if(!empty($return)){ foreach($return as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); return $return; } public static function updateByIds($alipayId,$sjId,$data) { xhUserUnite::updateByCondition(['alipayId'=>$alipayId,'sjId'=>$sjId], $data); self::getByIds($alipayId, $sjId); $cacheKey = dict::getCacheKey('xhUserUnite').'_'.$sjId.'_'.$alipayId; $params = [$cacheKey]; if(!empty($data)){ foreach($data as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); } }