deserialize($request->getContent(), PregDTO::class, 'json'); if ($dto->pattern === '') { throw new Exception('Empty regular expression'); } $preg = new Preg($dto); $result = $preg->exec(); $key = $preg->getHash(); $redis->setex(sprintf(self::STORE_KEY, $key), self::STORE_TTL, $serializer->serialize($dto, 'json')); return $this->json(array_merge((array)$result, ['hash' => $key])); } #[Route('/api/preg', name: 'api_preg_hash', methods: ["GET"])] public function hash(Request $request, \Redis $redis): Response { $json = $redis->get(sprintf(self::STORE_KEY, $request->query->get('hash'))); if ($json === false) { throw new NotFoundHttpException('Key not found.'); } return JsonResponse::fromJsonString($json); } }