Skip to content

Commit 6c2db3f

Browse files
authored
Add version check (#351)
* Add version check * Update Redis version in docs and README
1 parent 17f8718 commit 6c2db3f

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ Note: in order to use the PyTorch backend on Linux, at least `gcc 4.9.2` is requ
9292

9393
### Running the server
9494

95-
You will need a redis-server version 4.0.9 or greater. This should be
95+
You will need a redis-server version 5.0.7 or greater. This should be
9696
available in most recent distributions:
9797

9898
```sh
9999
redis-server --version
100-
Redis server v=4.0.9 sha=00000000:0 malloc=libc bits=64 build=c49f4faf7c3c647a
100+
Redis server v=5.0.7 sha=00000000:0 malloc=libc bits=64 build=c49f4faf7c3c647a
101101
```
102102

103103
To start Redis with the RedisAI module loaded:

docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RedisAI Quickstart
2-
RedisAI is a Redis module. To run it you'll need a Redis server (v4.0.9 or greater), the module's shared library, and its dependencies.
2+
RedisAI is a Redis module. To run it you'll need a Redis server (v5.0.7 or greater), the module's shared library, and its dependencies.
33

44
The following sections describe how to get started with RedisAI.
55

@@ -23,7 +23,7 @@ You can compile and build the module from its source code. The [Developer](devel
2323
### Prerequisites
2424
* CUDA needs to be installed for GPU support.
2525
* CMake 3.0 or higher needs to be installed.
26-
* Redis v4.0.9 or greater.
26+
* Redis v5.0.7 or greater.
2727

2828
### Get the Source Code
2929
You can obtain the module's source code by cloning the project's repository using git like so:

src/redisai.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@
2626
#include "redisai.h"
2727
#undef REDISAI_H_INCLUDE
2828

29+
int redisMajorVersion;
30+
int redisMinorVersion;
31+
int redisPatchVersion;
32+
33+
int rlecMajorVersion;
34+
int rlecMinorVersion;
35+
int rlecPatchVersion;
36+
int rlecBuild;
37+
38+
void getRedisVersion() {
39+
RedisModuleCtx *ctx = RedisModule_GetThreadSafeContext(NULL);
40+
RedisModuleCallReply *reply = RedisModule_Call(ctx, "info", "c", "server");
41+
assert(RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_STRING);
42+
size_t len;
43+
const char *replyStr = RedisModule_CallReplyStringPtr(reply, &len);
44+
45+
int n = sscanf(replyStr, "# Server\nredis_version:%d.%d.%d", &redisMajorVersion,
46+
&redisMinorVersion, &redisPatchVersion);
47+
48+
assert(n == 3);
49+
50+
rlecMajorVersion = -1;
51+
rlecMinorVersion = -1;
52+
rlecPatchVersion = -1;
53+
rlecBuild = -1;
54+
char *enterpriseStr = strstr(replyStr, "rlec_version:");
55+
if (enterpriseStr) {
56+
n = sscanf(enterpriseStr, "rlec_version:%d.%d.%d-%d", &rlecMajorVersion, &rlecMinorVersion,
57+
&rlecPatchVersion, &rlecBuild);
58+
if (n != 4) {
59+
RedisModule_Log(NULL, "warning", "Could not extract enterprise version");
60+
}
61+
}
62+
63+
RedisModule_FreeCallReply(reply);
64+
RedisModule_FreeThreadSafeContext(ctx);
65+
}
66+
67+
static inline int IsEnterprise() {
68+
return rlecMajorVersion != -1;
69+
}
2970

3071
/* ----------------------- RedisAI Module Commands ------------------------- */
3172

@@ -1192,6 +1233,23 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
11921233
if (RedisModule_Init(ctx, "ai", RAI_ENC_VER, REDISMODULE_APIVER_1)
11931234
== REDISMODULE_ERR) return REDISMODULE_ERR;
11941235

1236+
getRedisVersion();
1237+
RedisModule_Log(ctx, "notice", "Redis version found by RedisAI: %d.%d.%d - %s",
1238+
redisMajorVersion, redisMinorVersion, redisPatchVersion,
1239+
IsEnterprise() ? "enterprise" : "oss");
1240+
if (IsEnterprise()) {
1241+
RedisModule_Log(ctx, "notice", "Redis Enterprise version found by RedisAI: %d.%d.%d-%d",
1242+
rlecMajorVersion, rlecMinorVersion, rlecPatchVersion, rlecBuild);
1243+
}
1244+
1245+
if (redisMajorVersion < 5 ||
1246+
(redisMajorVersion == 5 && redisMinorVersion == 0 && redisPatchVersion < 7)) {
1247+
RedisModule_Log(ctx, "warning", "RedisAI requires Redis version equal or greater than 5.0.7");
1248+
return REDISMODULE_ERR;
1249+
}
1250+
1251+
RedisModule_Log(ctx, "notice", "RedisAI version: %d", RAI_ENC_VER);
1252+
11951253
int flags = RedisModule_GetContextFlags(ctx);
11961254

11971255
if(RedisAI_RegisterApi(ctx) != REDISMODULE_OK){

0 commit comments

Comments
 (0)