Redis ERR 未知命令'BZPOPMIN'

Redis ERR unknown command 'BZPOPMIN'

我按照 these instructions(即 sudo apt-get install redis-server)在 Windows 10 上的 Ubuntu Linux 子系统中安装了 Redis 版本 4.0.9。

我在 Django 频道上关注 this tutorial,我 运行 以下代码:

>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
>>> async_to_sync(channel_layer.receive)('test_channel')

当执行上面的最后一行时,我得到这个错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\xyz\Anaconda3\envs\django\lib\site-packages\asgiref\sync.py", line 120, in __call__
    return call_result.result()
  File "C:\Users\xyz\Anaconda3\envs\django\lib\concurrent\futures\_base.py", line 425, in result
    return self.__get_result()
  File "C:\Users\xyz\Anaconda3\envs\django\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
  File "C:\Users\xyz\Anaconda3\envs\django\lib\site-packages\asgiref\sync.py", line 180, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "C:\Users\xyz\Anaconda3\envs\django\lib\site-packages\channels_redis\core.py", line 485, in receive
    return (await self.receive_single(channel))[1]
  File "C:\Users\xyz\Anaconda3\envs\django\lib\site-packages\channels_redis\core.py", line 508, in receive_single
    index, channel_key, timeout=self.brpop_timeout
  File "C:\Users\xyz\Anaconda3\envs\django\lib\site-packages\channels_redis\core.py", line 345, in _brpop_with_clean
    result = await connection.bzpopmin(channel, timeout=timeout)
aioredis.errors.ReplyError: ERR unknown command 'BZPOPMIN'

this page,有人建议使用 Redis 版本 5。如何在 Windows 10 上安装 Redis 版本 5?关于如何解决这个问题还有其他想法吗?

在 Windows OS 中没有对 Redis 的官方支持。

但是,Microsoft 开发和维护 microsoftarchive/redis。它也不再受支持(旧版本可用)。关于在 windows 10 中安装版本 5,我进行了很长时间的搜索。但是没有运气。

你最好去 Memurai。 Memurai 与 Redis 协议 100% 兼容(也支持版本 5)。它可免费用于开发和测试。

编辑: 来自 Itamar 评论,你也可以使用 this 作为 Memurai

的替代品

这就是我解决这个问题的方法。 Ubuntu 18 安装 redis 4 但 ubuntu 20 安装 redis 5。您可以通过输入 redis-cli -v 找到您的 redis 版本。所以我从我的 windows 子系统中为 linux (WSL) 卸载 ubuntu 18 并重新安装 ubuntu 20。它工作得很好。

使用redis 5.0.9。它适用于相同的错误。

github.com/tporadowski/redis/releases

获取

我认为问题出在与 channels-redis 软件包版本的兼容性上!前段时间我已经测试过频道,它与 channels-redis 版本 2.4.2 配合使用时效果很好,最近它们的版本是 3.0.1 而且这个版本还不能正常使用我不知道为什么。

尝试使用 pip 安装 2.4.2 版本:

pip install channels-redis==2.4.2

版本问题。 试试旧的 我发现“2,3,4”任何版本都稳定且正常工作。 https://github.com/tporadowski/redis/releases

只需从此处下载适用于 Windows https://github.com/tporadowski/redis/releases 的最新版本的 Redis。

你不需要降级你的 channels-redis 等版本。Redis 的这个问题根本不是任何 python 包。

为了添加到@Marvin 的答案,对我来说它是相似的(可能是一些版本控制问题),我重新安装了 django_channels 和 django 到教程中指定的确切版本(3.0、2.2)并且它有效.不确定到底是什么有效,但建议检查一下:)

您需要安装redis的最新版本(6+):

$ sudo add-apt-repository ppa:redislabs/redis
$ sudo apt-get update
$ sudo apt-get install redis

然后重新启动 redis-server

在 Ubuntu 16.04

上出现同样的问题

同样,我在 Django Channels 网站上关注聊天应用程序 tutorial 并且遇到了同样的错误:

aioredis.errors.ReplyError: ERR unknown command 'BZPOPMIN'

我使用这些版本时出现的问题:

redis-server==3.0.6
channels==3.0.3
channels-redis==3.2.0

感谢@marvin-correia for his 我弄清楚了问题的原因是channels-redis包的版本!所以按照他的建议,我安装了channel-redis版本2.4.2,错误消失了。

pip install channels-redis==2.4.2

此外,我注意到频道包自动降级为 channels==2.4.0

我也会确认马文的回答。希望这会对某人有所帮助,但也请留在这里做笔记。

发展:

(此设置有效)考虑数据发送到并形成 http://localhost:8000

设置

Windows 10 运行 WSL 与 Ubuntu 20.04

  • Python==3.10
  • Django==4.0
  • Redis==5.0.7
  • channels-redis==3.3.1

生产

设置

  • Python==3.8
  • Ubuntu==16.04
  • Redis-server==3.0.6
  • chanels-redis==2.4.2
  • 频道==3.0.3

当我降级 channels-redis 时,它也会自动降级 channels。然后你可以强制升级到channels==3.0.3,但它会引发不兼容错误。另外,如果 2 个文件最有可能更新到 运行 Django 4.0

1 人在这儿 https://github.com/django/channels/issues/1609

我在 Windows 机器上遇到这个错误,我建议你在 docker 图像上使用 Redis,而不是在 windows 机器上使用 Redis 服务器。

通过 docker 图像和映射端口 6379 到 运行 redis 服务器的方法之一是:

  1. 启动docker桌面

  2. 在您的终端中输入以下命令。

    docker 运行 -p 6379:6379 -d redis:5