|
1 | 1 | class RedisGraph |
2 | 2 | def connect_to_server(options) |
3 | 3 | @connection = Redis.new(options) |
4 | | - @module_version = module_version() |
5 | | - raise ServerError, "RedisGraph module not loaded." if @module_version.nil? |
6 | | - raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if @module_version < 19900 |
| 4 | + check_module_version |
7 | 5 | end |
8 | 6 |
|
9 | 7 | # Ensure that the connected Redis server supports modules |
10 | 8 | # and has loaded the RedisGraph module |
11 | | - def module_version() |
| 9 | + def check_module_version() |
12 | 10 | redis_version = @connection.info["redis_version"] |
13 | 11 | major_version = redis_version.split('.').first.to_i |
14 | 12 | raise ServerError, "Redis 4.0 or greater required for RedisGraph support." unless major_version >= 4 |
15 | | - modules = @connection.call("MODULE", "LIST") |
| 13 | + |
| 14 | + begin |
| 15 | + modules = @connection.call("MODULE", "LIST") |
| 16 | + rescue Redis::CommandError |
| 17 | + # Ignore check if the connected server does not support the "MODULE LIST" command |
| 18 | + return |
| 19 | + end |
| 20 | + |
16 | 21 | module_graph = modules.detect { |_name_key, name, _ver_key, _ver| name == 'graph' } |
17 | | - module_graph[3] if module_graph |
| 22 | + module_version = module_graph[3] if module_graph |
| 23 | + raise ServerError, "RedisGraph module not loaded." if module_version.nil? |
| 24 | + raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if module_version < 19900 |
18 | 25 | end |
19 | 26 | end |
0 commit comments