$proyecto_id, 'ventas' => [] ]; $today = new DateTimeImmutable(); $redisKey = "ventas:facturacion:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}"; try { $output['ventas'] = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { try { $output['ventas'] = $ventaService->getIdsByProyecto($proyecto_id); $this->saveRedis($redisService, $redisKey, $output['ventas']); } catch (EmptyResult) {} } return $this->withJson($response, $output); } public function ventas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Venta $ventaService): ResponseInterface { $input = $request->getParsedBody(); $output = [ 'input' => $input, 'ventas' => [] ]; $ventas = explode(',', $input['ventas']); foreach ($ventas as $venta_id) { $redisKey = "ventas:facturacion:venta:{$venta_id}"; try { $venta = $this->fetchRedis($redisService, $redisKey); $output['ventas'] []= $venta; } catch (EmptyRedis) { try { $venta = $ventaService->getFacturacionById($venta_id); $output['ventas'] []= $venta; $this->saveRedis($redisService, $redisKey, $venta); } catch (EmptyResult $exception) { $this->logger->notice($exception); } } } return $this->withJson($response, $output); } }