ERR SELECT is not allowed in cluster mode: SELECT is not allowed in cluster mode(集群模式下不允许 SELECT)
Redis含义
在 Redis Cluster 模式下,您试图用 SELECT 切换到其他逻辑数据库(DB 索引)。集群模式只支持数据库 0;无法使用多个 DB。
原因
在单机 Redis 上用 SELECT 在 DB 0-15 之间切换的应用,迁移到 Redis Cluster 后仍在发送相同的命令。由于集群架构按槽分布数据,不支持多 DB 的概念。
解决方法
在集群模式下删除 SELECT 调用;只使用 DB 0。如果需要逻辑隔离,使用键前缀(命名空间)(例如 app1:key)。如果某些键必须一起处理,使用哈希标签({user123})使它们落在同一槽中。使应用配置能够感知集群。
同一数据库的其他条目
- NOTBUSY No scripts in execution right nowNo scripts in execution right now(当前没有正在执行的脚本)
- DENIED Redis is running in protected modeRedis is running in protected mode(Redis 正以保护模式运行)
- ERR Can't execute '<cmd>': only (P|S)SUBSCRIBE / (P|S)UNSUBSCRIBE / PING / QUIT / RESET are allowed in this contextCommand not allowed in subscribe context(在订阅上下文中不允许该命令)
- ERR wrong number of arguments for commandWrong number of arguments for command(命令的参数数量错误)
- ERR Background save already in progressBackground save already in progress(后台保存已在进行中)
- ERR bit offset is not an integer or out of rangeBit offset is not an integer or out of range(位偏移量不是整数或超出范围)
- ERR Protocol error: invalid multibulk lengthProtocol error: invalid multibulk length(协议错误:无效的 multibulk 长度)