我正在尝试将 Symfony2 与 Azure 上的 Redis 服务器连接,但无法弄清楚在哪里放置主机名、端口和密钥以及其他详细信息(如果需要,但我不知道)。
composer.json
"predis/predis": "1.*",
"snc/redis-bundle": "1.1.x-dev"
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
redis://[password@]host[:port][/db]
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;