无法使用 ServiceStack.Redis 库连接 Redis 缓存服务器

Unable to connect Redis Cache server using ServiceStack.Redis library

我已经安装 PM> Install-Package ServiceStack.Redis 并使用以下代码连接 azure redis 缓存。

我想我错过了连接字符串,因为我没有在 host

中给出 PRIMARY KEY
string host = "mydemo.redis.cache.windows.net";
            var redisManager = new PooledRedisClientManager(host);
            using (var redisClient = redisManager.GetClient())
            {
                IRedisTypedClient<Customer> redis = redisClient.As<Customer>();

获取错误:

{"could not connect to redis Instance at mydemo.redis.cache.windows.net:6379"}

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 11.22.216.225:6379

这是一个基本的网络连接错误。您需要确保您有权连接到 mydemo.redis.cache.windows.net (11.22.216.225:6379) 上的 TCP 端口 6379,并根据需要打开任何防火墙规则。

您可以使用 telnet 或 运行 redis-cli.exe(来自 redis-windows) on the same server you're trying to use ServiceStack.Redis,例如:

测试 TCP 连接
redis-cli -h 11.22.216.225 -p 6379

SSL Redis Connections to Azure Redis

如果您是 trying to connect to a redis-server on Azure,则连接字符串通常采用以下格式:

{AzureRedisKey}@servicestackdemo.redis.cache.windows.net?ssl=true 

?ssl=true 选项表示在默认端口 Azure SSL 端口 6380.

上使用 SSL