【问题标题】:Connect to Azure Redis Cache as Service using Jedis使用 Jedis 连接到 Azure Redis 缓存即服务
【发布时间】:2017-12-08 11:08:28
【问题描述】:

我正在尝试使用他们网站上提供的示例代码从 Azure 外部连接到 Azure Redis 缓存服务

            boolean useSsl = false;
            /* In this line, replace <name> with your cache name: */
            JedisShardInfo shardInfo = new JedisShardInfo("HOST_NAME", 6379, useSsl);
            shardInfo.setPassword(ACCESS_KEY); /* Use your access key. */
            shardInfo.setConnectionTimeout(999999);
            shardInfo.setSoTimeout(999999);
            Jedis jedis = new Jedis(shardInfo);
            jedis.set("foo", "bar");
            String value = jedis.get("foo");

我在从 Azure 外部执行程序时遇到以下异常

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: recv failed
       at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
       at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
       at redis.clients.jedis.Protocol.process(Protocol.java:151)
       at redis.clients.jedis.Protocol.read(Protocol.java:215)
       at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
       at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
       at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:96)
       at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
       at redis.clients.jedis.BinaryClient.set(BinaryClient.java:110)
       at redis.clients.jedis.Client.set(Client.java:47)
       at redis.clients.jedis.Jedis.set(Jedis.java:120)
       at com.oriental.redis.cache.TestClient.main(TestClient.java:65)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
       at java.net.SocketInputStream.socketRead0(Native Method)
       at java.net.SocketInputStream.socketRead(Unknown Source)
       at java.net.SocketInputStream.read(Unknown Source)
       at java.net.SocketInputStream.read(Unknown Source)
       at java.net.SocketInputStream.read(Unknown Source)
       at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196)
       ... 11 more

该错误表明 Azure Redis 服务器从未确认连接。 我使用的是基本 Azure 订阅,因此没有创建任何高级实例,文档说防火墙/IP 访问过滤器仅适用于高级版本的 Azure Redis 缓存。

这让我很困惑。任何帮助将不胜感激。

【问题讨论】:

    标签: java azure caching azure-redis-cache


    【解决方案1】:

    如果要连接到端口 6379(非 ssl 端口),则必须显式打开该端口。默认情况下,Azure Redis 需要加密连接(通过端口 6380)。详情请见https://docs.microsoft.com/en-us/azure/redis-cache/cache-configure#access-ports。

    【讨论】:

    • 感谢@JonCole,我已经打开了 6379,但问题是网络防火墙阻止了与外部 azure 云的连接。一旦端口的传出连接被解除阻塞,它就开始正常工作了。
    猜你喜欢
    • 2012-03-17
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多