Skip to content

Skip module check if server doesn't support MODULE LIST #16

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

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for check_module_version is too high. [16.58/15]
Metrics/MethodLength: Method has too many lines. [12/10]
Style/DefWithParentheses: Omit the parentheses in defs when the method doesn't accept any arguments.

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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

rescue Redis::CommandError
# Ignore check if the connected server does not support the "MODULE LIST" command
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [87/80]

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?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if module_version < 19900
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Metrics/LineLength: Line is too long. [101/80]
Style/NumericLiterals: Use underscores(_) as decimal mark and separate every 3 digits with them.

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}]]])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
Metrics/LineLength: Line is too long. [94/80]

end
end
end