【问题标题】:How can I resolve redis error on connection problem?如何解决连接问题的redis错误?
【发布时间】:2019-07-16 11:45:33
【问题描述】:

最近我正在将我的应用程序从 Symfony 3.4 升级到 Symfony 4.2。我遇到错误告诉read error on connection

这是堆栈跟踪:

at var/cache/dev/ContainerRUEbk9e/Redis_ca5fc0f.php:312
  at Redis->get('DoctrineNamespaceCacheKey[]')
     (var/cache/dev/ContainerRUEbk9e/Redis_ca5fc0f.php:312)
  at Redis_ca5fc0f->get('DoctrineNamespaceCacheKey[]')
     (vendor/doctrine/cache/lib/Doctrine/Common/Cache/RedisCache.php:47)
  at Doctrine\Common\Cache\RedisCache->doFetch('DoctrineNamespaceCacheKey[]')
     (vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php:200)
  at Doctrine\Common\Cache\CacheProvider->getNamespaceVersion()
     (vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php:177)
  at Doctrine\Common\Cache\CacheProvider->getNamespacedId('9f7b27184e58ac025013b8c22fbdfa8a')
     (vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php:60)
  at Doctrine\Common\Cache\CacheProvider->fetch('9f7b27184e58ac025013b8c22fbdfa8a')
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:271)
  at Doctrine\ORM\Query->_parse()
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:295)
  at Doctrine\ORM\Query->_doExecute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:967)
  at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, 1)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:922)
  at Doctrine\ORM\AbstractQuery->execute(null, 1)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:726)
  at Doctrine\ORM\AbstractQuery->getResult()
     (src/Acme/AcmeBundle/Controller/AcmeController.php:1461)
  at Acme\AcmeBundle\Controller\AcmeController->acmeAction(object(Request))
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/app_dev.php:35)
  at runSymfony()
     (public/app_dev.php:39)
  at require('/var/www/html/project/Website/public/app_dev.php')
     (vendor/symfony/symfony/src/Symfony/Bundle/WebServerBundle/Resources/router.php:42)

请看问题

【问题讨论】:

  • 有缓存目录权限吗?你的缓存显然有问题
  • @AythaNzt 是的,它拥有所有权限。
  • 你正在执行什么命令来清理缓存?如果您不使用这些,请尝试: php bin/console cache:clear --no-warmup --env=prod php bin/console cache:warmup --env=prod php bin/console cache:clear --no-预热 php bin/控制台缓存:预热
  • 我已经清除了缓存

标签: php symfony doctrine-orm redis symfony4


【解决方案1】:

这可能会有所帮助。之前我的配置是这样的:

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
        session:
            type: phpredis
            alias: session
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
        doctrine:
            type: phpredis
            alias: doctrine
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
    session:
        client: session
        prefix: session:main

    doctrine:
        metadata_cache:
            client: doctrine
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
            namespace: "%kernel.root_dir%"
        result_cache:
            client: doctrine
            entity_manager: [default, read]  # you may specify multiple entity_managers
        query_cache:
            client: doctrine
            entity_manager: default

改为如下

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
        session:
            type: predis
            alias: session
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
        doctrine:
            type: predis
            alias: doctrine
            dsn: "%redis_dsn%"
            options:
                read_write_timeout: "%redis_read_write_timeout%"
    session:
        client: session
        prefix: session:main

    doctrine:
        metadata_cache:
            client: doctrine
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
            namespace: "%kernel.root_dir%"
        result_cache:
            client: doctrine
            entity_manager: [default, read]  # you may specify multiple entity_managers
        query_cache:
            client: doctrine
            entity_manager: default

可能会帮助别人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 2020-06-25
    • 2015-05-08
    • 2023-01-16
    • 2012-05-20
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    相关资源
    最近更新 更多