Skip to content

Commit

Permalink
Skip module check if server doesn't support MODULE LIST (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreylovitz authored Sep 22, 2021
1 parent c28cc03 commit 9ffba1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lib/redisgraph/connection.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
class RedisGraph
def connect_to_server(options)
@connection = Redis.new(options)
@module_version = module_version()
raise ServerError, "RedisGraph module not loaded." if @module_version.nil?
raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if @module_version < 19900
check_module_version
end

# Ensure that the connected Redis server supports modules
# and has loaded the RedisGraph module
def module_version()
def check_module_version()
redis_version = @connection.info["redis_version"]
major_version = redis_version.split('.').first.to_i
raise ServerError, "Redis 4.0 or greater required for RedisGraph support." unless major_version >= 4
modules = @connection.call("MODULE", "LIST")

begin
modules = @connection.call("MODULE", "LIST")
rescue Redis::CommandError
# Ignore check if the connected server does not support the "MODULE LIST" command
return
end

module_graph = modules.detect { |_name_key, name, _ver_key, _ver| name == 'graph' }
module_graph[3] if module_graph
module_version = module_graph[3] if module_graph
raise ServerError, "RedisGraph module not loaded." if module_version.nil?
raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if module_version < 19900
end
end
2 changes: 1 addition & 1 deletion spec/redisgraph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_graph()
it "should print property strings correctly after updates" do
q = """MATCH (a {name: 'src1'}) RETURN a"""
res = @r.query(q)
expect(res.resultset).to eq([[[{"name"=>"src1"}, {"color"=>"cyan"}, {"newval"=>TRUE}]]])
expect(res.resultset).to eq([[[{"name"=>"src1"}, {"color"=>"cyan"}, {"newval"=>true}]]])
end
end
end

0 comments on commit 9ffba1d

Please sign in to comment.