【问题标题】:Redis CLI disconnects immediately when setting a key in Azure Redis Cache在 Azure Redis 缓存中设置键时,Redis CLI 立即断开连接
【发布时间】:2020-08-31 21:28:34
【问题描述】:

我在基本 250MB 层下预配了一个 Azure Redis 缓存,TLS 版本设置为 Default。我使用了 Windows 10 版本 2004 中的 Redis CLI。我还尝试使用 Multipass Ubuntu Linux VM 中的 Redis CLI,并得到了相同的结果。

我运行以下命令以获取交互式 Redis CLI 提示符,该提示符在 10 秒左右非常缓慢:

redis-cli -h mytestcache658.redis.cache.windows.net -p 6380 -a 'REDACTEDREDACTED'

然后我从交互式 CLI 运行一个简单的 Redis 命令:

mytestcache658.redis.cache.windows.net:6380> SET FirstName Trevor

一运行此命令,我立即与 Azure Redis 缓存断开连接。

在 Windows 10 上,Redis CLI 版本 3.2.100,我收到此错误:

Error: An existing connection was forcibly closed by the remote host.

在带有 Redis CLI 版本 5.0.7 的 Ubuntu Linux 上,我收到此错误:

Error: Connection reset by peer

问题:我具体如何使用 Azure Redis 缓存?它似乎根本不起作用。

【问题讨论】:

    标签: azure redis


    【解决方案1】:

    显然,在 Azure 中运行的 Redis 版本是旧版本 (4.0)。根据their documentation,Redis 直到 6.0 版才支持 TLS,作为可选功能。当然,Azure 门户中实际上并没有告诉您这一点。

    最终,在与几位同事商议后,我遇到了 broken link 到 6 year-old blog post 的一个无关主题,据称涉及使用 stunnel 首先建立 TLS 连接。

    在 Google 搜索 stunnel azure redis 后,我找到了一些文档的链接,其中描述了连接到 Azure Redis 的两种方法:

    1. 禁用 TLS(不推荐,原因很明显)
    2. 使用stunnel to establish a TLS connection

    我选择在 Windows Subsystem for Linux (WSL) 上安装 stunnel,而不是使用 Windows 版本的 stunnel。

    sudo apt-get install stunnel
    

    然后,我创建了一个配置文件,将 stunnel 指向我的 Azure Redis 缓存。

    foreground = yes
    
    [redis-cli]
    client = yes
    accept = 127.0.0.1:6380
    connect = mytestcache658.redis.cache.windows.net:6380
    

    然后我只需在前台运行stunnel,使用单独的 tmux 窗格,引用配置文件。

    stunnel stunnel.conf
    

    在另一个 tmux 窗格中,我运行 redis-cli 并连接到远程 Azure Redis 缓存。您可以使用-a参数指定主密钥/密码,也可以匿名连接,然后使用redis-cli中的auth REDACTED命令进行身份验证。

    redis-cli -p 6380 -a REDACTEDREDACTED
    

    或

    redis-cli -p 6380
    redis> AUTH REDACTED
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2022-11-25
      相关资源
      最近更新 更多