【问题标题】:Using Redis on Azure with Symfony2在 Azure 上使用 Redis 和 Symfony2
【发布时间】:2016-02-26 10:12:55
【问题描述】:

我正在尝试将 Symfony2 与 Azure 上的 Redis 服务器连接,但不知道将主机名、端口和密钥以及其他详细信息放在哪里(如果需要,我不知道)。

composer.json

"predis/predis": "1.*",
"snc/redis-bundle": "1.1.x-dev"

根据this tutorial配置的config.yml

snc_redis:
  # configure predis as client
  clients:
      default:
          type: predis
          alias: default
          dsn: projectrdev.redis.cache.windows.net
      doctrine:
          type: predis
          alias: doctrine
          dsn: projectrdev.redis.cache.windows.net
  # configure doctrine caching
  doctrine:
      metadata_cache:
          client: doctrine
          entity_manager: default
          document_manager: default
      result_cache:
          client: doctrine
          entity_manager: [default]
      query_cache:
          client: doctrine
          entity_manager: default

根据 Predis documentation 可以配置客户端,但现在确定它在 Symfony 环境中是如何工作的。

【问题讨论】:

标签: php symfony azure doctrine-orm redis


【解决方案1】:

首先,我们应该为 PHP 集成启用非 SSL 端点。

并且需要将redis dsn连接字符串组合成如下格式:redis://[password@]host[:port][/db]

例如,在您的 symfony2 应用程序的 config.yml 文件中,您可以进行如下配置: snc_redis: clients: default: type: predis alias: default dsn: redis://{password}@{your_redis_name}.redis.cache.windows.net

并在控制器功能中进行测试: use Snc\RedisBundle\Doctrine\Cache\RedisCache; use Predis\Client; ... ... $redis = $this->container->get('snc_redis.default'); $val = $redis->incr('foo:bar'); echo $val;

【讨论】:

  • 密码是多少?主访问密钥?
  • @ChrisHarrison,是的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
  • 2013-08-12
  • 2018-03-25
  • 1970-01-01
  • 2012-06-19
相关资源
最近更新 更多