Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ bug ]azure redis 检查连接报错 #1451

Closed
carllhw opened this issue Apr 6, 2022 · 7 comments
Closed

[ bug ]azure redis 检查连接报错 #1451

carllhw opened this issue Apr 6, 2022 · 7 comments

Comments

@carllhw
Copy link

carllhw commented Apr 6, 2022

在提交 issue 前,请查阅以下资源,请先进行搜索来保证没有类似的 issue。
文档 | FAQ

重现步骤

添加azure redis实例,点击测试连接报错

期待结果和实际结果

期待结果:
成功

实际结果:
无法连接实例,\nunknown command CONFIG, with args beginning with: GET, databases,

截图

错误日志

[2022-04-06 20:55:42,775][MainThread:139861942777664][task_id:default][redis.py:53][WARNING]- Redis CONFIG GET databases 执行报错,异常信息:unknown command `CONFIG`, with args beginning with: `GET`, `databases`,

版本信息

应用版本/分支:1.8.3

部署方式:Docker

@carllhw
Copy link
Author

carllhw commented Apr 6, 2022

Azure Redis 缓存中不支持 Redis 命令

因为 Azure Redis 缓存实例的配置和管理由 Microsoft 进行管理,所以禁用了以下命令。 如果尝试调用它们,将收到一条类似于 "(error) ERR unknown command" 的错误消息。

  • BGREWRITEAOF
  • BGSAVE
  • CONFIG
  • DEBUG
  • MIGRATE
  • SAVE
  • SHUTDOWN
  • SLAVEOF
  • CLUSTER - 群集写命令已禁用,但允许使用只读群集命令。

@LeoQuote
Copy link
Collaborator

LeoQuote commented Apr 7, 2022

有什么其他检查的方案吗?

@carllhw
Copy link
Author

carllhw commented Apr 7, 2022

如果无法执行报错则默认16,然后检查info Keyspace里现有最大的max db,如果比16大就按照max db来

@carllhw
Copy link
Author

carllhw commented Apr 7, 2022

@chenyu1st
Copy link
Contributor

现在最新的1.9.1仍然会报错这个问题哦

@ouyangxudu
Copy link

1.9.1  docker 部署,连接 ucloud 的云 redis 也是这个报错,日志
[2023-04-28 17:06:22,283][MainThread:139630832527168][task_id:default][redis.py:69][WARNING]- Redis CONFIG GET databases 执行报错,异常信息:unknown command CONFIG, with args beginning with: GET, databases,

页面显示:
image

@ouyangxudu
Copy link

1.9.1  docker 部署,连接 ucloud 的云 redis 也是这个报错,日志 [2023-04-28 17:06:22,283][MainThread:139630832527168][task_id:default][redis.py:69][WARNING]- Redis CONFIG GET databases 执行报错,异常信息:unknown command CONFIG, with args beginning with: GET, databases,

页面显示: image

修改sql/engines/redis.py 解决问题:
def get_all_databases(self, **kwargs):
"""
获取数据库列表
:return:
"""
result = ResultSet(full_sql="CONFIG GET databases")
conn = self.get_connection()
try:
# 旧版的 Redis 使用 CONFIG GET 命令
rows = conn.config_get("databases")["databases"]
except Exception as e:
logger.warning(f"Redis xxx CONFIG GET databases 执行报错,异常信息:{e}")
# 新版的 Redis 不再支持 CONFIG GET 命令,使用另一种方式获取数据库数
dbs = [
int(i.split("db")[1])
for i in conn.info("Keyspace").keys()
if len(i.split("db")) == 2
]
# 如果获取失败,可以设置默认的数据库数,这里设置为16
rows = max(dbs, [16])[-1]

db_list = [str(x) for x in range(int(rows)]
result.rows = db_list
return result

容器内,重新加载应用

/bin/bash /opt/archery/src/docker/startup.sh

@LeoQuote LeoQuote closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants