我正尝试使用其网站上提供的示例代码从Azure外部连接到Azure Reddis缓存服务
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缓存的高级版本。
这令我感到困惑。任何帮助将不胜感激。
答案 0 :(得分:0)
如果要连接到端口6379(非ssl端口),则必须明确打开该端口。默认情况下,Azure Redis需要加密连接(通过端口6380)。有关详细信息,请参阅https://docs.microsoft.com/en-us/azure/redis-cache/cache-configure#access-ports。