Wir haben ein neues Symfony-Setup mit Redis als Caching-Mechanismus. Wir m?chten eine Verbindung zu einem bestimmten Host herstellen, nicht zum Standard-Localhost. In der Produktion gibt ./bin/console debug:dotenv den richtigen REDIS_HOST aus. Dies ist in unserer .env und .env.local.php konfiguriert.
Der Fehler, den wir erhalten, ist:
Verbindung abgelehnt: tcp:127.0.0.1/6379
Das ist unsere Konfiguration:
services.yml
services: Redis: # you can also use \RedisArray, \RedisCluster or \Predis\Client classes class: \Predis\Client calls: - connect: - '%env(REDIS_HOST)%' - '%env(int:REDIS_PORT)%' Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler: arguments: - '@Redis' - prefix: sp_ss_ - ttl: 1800
cache.yml
framework: cache: app: cache.adapter.redis default_redis_provider: 'Redis' pools: site.cache: adapter: cache.app
Und unsere .env-Datei:
APP_ENV=prod APP_SECRET=**** MESSENGER_TRANSPORT_DSN=redis://redis.local:6379/messages REDIS_HOST=redis.local REDIS_PORT=6379 REDIS_URL=redis://redis.local:6379
Symfony 的文檔建議使用“calls -> connect”,但僅當您將類定義為“Redis”時才使用它。當您使用'\Predis\Client'時,您需要使用以下設置:
“config/services.yaml”
Redis: # you can also use \RedisArray, \RedisCluster or \Predis\Client classes class: \Predis\Client # See all parameters here: https://github.com/predis/predis/wiki/Connection-Parameters#list-of-connection-parameters arguments: - host: '%env(REDIS_HOST)%' - port: '%env(int:REDIS_PORT)%' # uncomment the following if your Redis server requires a password # - password: '%env(REDIS_PASSWORD)%'
我還使用“\Predis\Client”,更改為“arguments”后,連接在這里工作。
有關更多參數(shù)參考,請查看此鏈接(連接參數(shù)列表).