我有一个在单个子网内的 VNet 中运行的 Azure 函数。我还设置了一个可公开访问的 Azure Redis 缓存。最初,Azure Function 能够与 Redis 缓存进行通信,没有任何问题。但是,出于安全目的,我将 Redis 缓存中的 Azure Function 的出站 IP 列入白名单。从那时起,我就遇到了超时问题。
Method: PutKeysAsync error while inserting key: key and value: akhil, Error: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=SET, timeout: 5000, inst: 0, qu: 0, qs: 0, aw: False, bw: CheckingForTimeout, rs: NotStarted, ws: Initializing, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 4, serverEndpoint: test-pr-analyzer-redis-cache.redis.cache.windows.net:6380, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: pd1sdwk001NH9(SE.Redis-v2.8.0.27420), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=2,Free=32765,Min=1,Max=32767), POOL: (Threads=5,QueuedItems=0,CompletedItems=4712,Timers=12), v:
2.8.0.27420 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeout
请帮我解决问题。
提前致谢
在 VNet 中运行的 Azure 函数无法连接到列入白名单的 Azure Redis 缓存。
以下是功能应用程序无法访问
Redis cache
的原因。
要永久解决该问题,请确保使用虚拟网络 NAT 网关将流量从 Function App 子网路由到 Redis 缓存。请按照以下步骤使用 NAT 网关建立连接。
VNet
和Subnet
的NAT网关,并在出站IP部分选择之前创建的公共IP。
创建 NAT 网关后,出站流量将通过 NAT 网关的 IP 地址。要在 Azure Function App 和 Redis 缓存之间建立连接,请确保在 Redis 缓存防火墙中添加与 NAT 网关关联的公共 IP 地址。
NAT 网关详细信息
Redis 缓存防火墙设置
将公网IP地址添加到Redis缓存防火墙后,Function App就可以与Redis缓存通信了。
Redis 缓存结果