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”后,连接在这里工作。
有关更多参数参考,请查看此链接(连接参数列表).