Symfony и predis: не удалось получить ключ - PullRequest
0 голосов
/ 29 июня 2019

я пытаюсь получить простой пример запуска symfony / predis.Но если я пытаюсь что-то сохранить / прочитать на моем сервере Redis Docker, я получаю следующее сообщение об ошибке:

Ошибка при чтении строки с сервера.[tcp: // localhost: 5378]

  key" => "thisIsACacheKey"
  "exception" => ConnectionException^ {#3532 ▼
    -connection: StreamConnection {#3766 …}
    #message: "Error while reading line from the server. [tcp://localhost:5378]"
    #code: 0
    #file: "C:\cacheExmaple\vendor\predis\predis\src\Connection\AbstractConnection.php"
    #line: 155

Я не знаю, в этом ли проблема с конфигурацией docker или symfony / predis.cache.yaml:

framework:
    cache:
        # Put the unique name of your app here: the prefix seed
        # is used to compute stable namespaces for cache keys.
        prefix_seed: aj/cacheExample

        # Redis
        app: cache.adapter.redis
        default_redis_provider: redis://localhost:5378

docker ps:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
8c18a3e37e74        redis:3.2-alpine    "docker-entrypoint.s…"   43 seconds ago      Up 41 seconds       0.0.0.0:5378->5378/tcp, 6379/tcp    projectmonatg_redis_1

Вот пример HomeController для тестирования функции кэширования.

class HomeController extends AbstractController
{
    public function __construct(AdapterInterface $cache)
    {
        $this->cache = $cache;
    }

    /**
     * @Route("/", name="home")
     */
    public function index()
    {
        $cacheKey = 'thisIsACacheKey';
        $item = $this->cache->getItem($cacheKey);

        $itemCameFromCache = true;
        if (!$item->isHit()) {
            $itemCameFromCache = false;
            $item->set('this is some data to cache');
            $item->expiresAfter(new DateInterval('PT10S')); // the item will be cached for 10 seconds
            $this->cache->save($item);

        }

        return $this->render('home/index.html.twig', ['isCached' => $itemCameFromCache ? 'true' : 'false']);
    }
}
...