fix: sentinel resp3 support
fix https://github.com/apache/kvrocks/issues/3285
English / 中文
Root Cause Analysis
The issue occurs because Kvrocks reports its Redis version as 4.0.0 (defined in src/server/server.h:61), while RESP3 protocol was introduced in Redis 6.0.
Most Redis client libraries perform version checking before attempting to use RESP3. When clients see a server version below 6.0, they skip the HELLO 3 command entirely and default to RESP2, even if the server actually supports RESP3.
How Redis Clients Check Version
- Client connects to Redis/Kvrocks
- Client checks server version (via
INFOorHELLOresponse) - If version < 6.0: Client assumes RESP3 is not supported and uses RESP2
- If version >= 6.0: Client sends
HELLO 3to negotiate RESP3
Why This Affects Sentinel Connections
When connecting through Redis Sentinel:
- Sentinel provides the master address to the client
- Client connects to the master and checks its version
- If Kvrocks reports version
4.0.0, the client library won't attempt RESP3 - This happens regardless of the
resp3-enabledconfiguration
Solution
Update REDIS_VERSION from "4.0.0" to "7.0.0" in src/server/server.h.
Why 7.0.0 Instead of 6.0.0?
While RESP3 was introduced in Redis 6.0, Redis 7.0 is the first version with full, production-ready RESP3 support. Some client libraries may have additional checks or optimizations specifically for Redis 7.0+. Using version 7.0.0 ensures maximum compatibility with all modern Redis clients.
Code Change Required
// src/server/server.h:61
-constexpr const char *REDIS_VERSION = "4.0.0";
+constexpr const char *REDIS_VERSION = "7.0.0";
Test Updates
Also update the test expectations in:
tests/gocase/unit/hello/hello_test.go(lines 48, 57)
-require.EqualValues(t, "4.0.0", rList[3])
+require.EqualValues(t, "7.0.0", rList[3])
根本原因分析
问题的根源在于 Kvrocks 报告的 Redis 版本为 4.0.0(定义在 src/server/server.h:61),而 RESP3 协议是在 Redis 6.0 中引入的。
大多数 Redis 客户端库在尝试使用 RESP3 之前会进行版本检查。 当客户端看到服务器版本低于 6.0 时,它们会完全跳过 HELLO 3 命令,直接使用 RESP2,即使服务器实际上支持 RESP3。
Redis 客户端如何检查版本
- 客户端连接到 Redis/Kvrocks
- 客户端检查服务器版本(通过
INFO或HELLO响应) - 如果版本 < 6.0:客户端假定不支持 RESP3,使用 RESP2
- 如果版本 >= 6.0:客户端发送
HELLO 3来协商 RESP3
为什么这会影响 Sentinel 连接
通过 Redis Sentinel 连接时:
- Sentinel 向客户端提供 master 地址
- 客户端连接到 master 并检查其版本
- 如果 Kvrocks 报告版本为
4.0.0,客户端库不会尝试 RESP3 - 这与
resp3-enabled配置无关
解决方案
将 REDIS_VERSION 从 "4.0.0" 更新为 "7.0.0",位置在 src/server/server.h。
为什么是 7.0.0 而不是 6.0.0?
虽然 RESP3 在 Redis 6.0 中引入,但 Redis 7.0 是第一个具有完整、生产就绪的 RESP3 支持的版本。一些客户端库可能针对 Redis 7.0+ 有额外的检查或优化。使用版本 7.0.0 可以确保与所有现代 Redis 客户端的最大兼容性。
需要的代码更改
// src/server/server.h:61
-constexpr const char *REDIS_VERSION = "4.0.0";
+constexpr const char *REDIS_VERSION = "7.0.0";
测试更新
同时需要更新以下测试文件中的期望值:
tests/gocase/unit/hello/hello_test.go(第 48、57 行)
-require.EqualValues(t, "4.0.0", rList[3])
+require.EqualValues(t, "7.0.0", rList[3])
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
62.5% Coverage on New Code
1.1% Duplication on New Code