Skip to content
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

Fix: Support unix socket connection to Redis #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sachinjogi
Copy link

@sachinjogi sachinjogi commented Sep 24, 2024

This should fix FalkorDB/falkordb-bulk-loader#11.

Summary by CodeRabbit

  • New Features
    • Enhanced connection flexibility by allowing the use of a Unix socket path in the from_url method for establishing connections.

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes in this pull request involve the from_url class method of the FalkorDB class in falkordb.py. A new keyword argument, unix_socket_path, is introduced, allowing the method to accept a Unix socket path for establishing connections. This modification enhances the flexibility of the connection parameters, particularly for users migrating from systems that utilize Unix sockets.

Changes

Files Change Summary
falkordb/falkordb.py Updated from_url method to include a new keyword argument unix_socket_path in kwargs.

Assessment against linked issues

Objective Addressed Explanation
Falkordb Bulk Insert does not support --unix-socket-path option (#11)

🐰 In the land of code, a change was made,
A socket path for rabbits, in the shade.
From TCP to Unix, connections now flow,
With from_url updated, watch the data grow!
Hopping through errors, we’ll leap with delight,
FalkorDB’s magic shines ever so bright! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fb56ead and 3b23f90.

Files selected for processing (1)
  • falkordb/falkordb.py (1 hunks)
Additional comments not posted (2)
falkordb/falkordb.py (2)

178-178: Summary: Unix socket support added successfully.

The implementation of Unix socket support in the from_url method is correct and aligns with the PR objectives. This change enhances the flexibility of the FalkorDB class by allowing connections via Unix sockets.

Key points:

  1. The change correctly adds unix_socket_path to the kwargs dictionary.
  2. It uses the appropriate key ("path") from connection_kwargs.
  3. The implementation is consistent with Redis's handling of Unix socket connections.

To ensure a robust implementation:

  1. Verify full Unix socket support throughout the class (see the verification script in a previous comment).
  2. Add specific unit tests for Unix socket connections.
  3. Update documentation to reflect the new functionality.
  4. Ensure no regressions for existing TCP connections.

Overall, this change is a valuable addition to the FalkorDB class, addressing the issue raised in #11 and improving compatibility for users migrating from RedisGraph to FalkorDB.


178-178: LGTM! Verify full Unix socket support.

The addition of unix_socket_path to kwargs is correct and aligns with the PR objective of supporting Unix socket connections. This change should allow the FalkorDB class to handle Unix socket URLs as requested in the linked issue.

To ensure full Unix socket support, please run the following verification script:

This script will help ensure that the unix_socket_path is properly handled throughout the FalkorDB class and related files.

Verification successful

Verified! Unix socket support is correctly implemented.

The unix_socket_path is properly set and utilized within both the FalkorDB class and its asynchronous counterpart, ensuring full support for Unix socket connections.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Unix socket support in FalkorDB class

# Test 1: Check if unix_socket_path is properly passed to the FalkorDB constructor
rg -A 10 'def __init__' falkordb/falkordb.py

# Test 2: Verify that the unix_socket_path is used in establishing the connection
rg -A 5 'unix_socket_path' falkordb/falkordb.py

# Test 3: Check for any potential issues with Unix socket handling in other parts of the code
rg 'unix[_-]socket' falkordb/

Length of output: 1352

@@ -175,6 +175,7 @@ def from_url(cls, url: str, **kwargs) -> "FalkorDB":
kwargs["port"] = connection_kwargs.get("port", 6379)
kwargs["username"] = connection_kwargs.get("username")
kwargs["password"] = connection_kwargs.get("password")
kwargs["unix_socket_path"] = connection_kwargs.get("path")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Suggest additional tests and documentation updates.

While the change correctly adds Unix socket support to the from_url method, consider the following suggestions to ensure comprehensive implementation:

  1. Add unit tests specifically for Unix socket connections using the from_url method.
  2. Update the class and method docstrings to mention Unix socket support.
  3. Consider adding an example of using a Unix socket connection in the class docstring.

Here's a suggested update for the class docstring:

class FalkorDB:
    """
    FalkorDB Class for interacting with a FalkorDB server.

    Supports both TCP and Unix socket connections.

    Usage examples::
        from falkordb import FalkorDB
        # Connect to the database using TCP and select the 'social' graph
        db = FalkorDB()
        graph = db.select_graph("social")

        # Connect using a Unix socket
        db_unix = FalkorDB.from_url("unix:///path/to/redis.sock")
        graph_unix = db_unix.select_graph("social")

        # Get a single 'Person' node from the graph and print its name
        result = graph.query("MATCH (n:Person) RETURN n LIMIT 1").result_set
        person = result[0][0]
        print(person.properties['name'])
    """

Also, consider adding a unit test for Unix socket connections:

def test_from_url_unix_socket():
    url = "unix:///path/to/redis.sock"
    db = FalkorDB.from_url(url)
    assert db.connection.connection_pool.connection_kwargs['unix_socket_path'] == "/path/to/redis.sock"
    assert db.connection.connection_pool.connection_kwargs['host'] is None
    assert db.connection.connection_pool.connection_kwargs['port'] is None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Falkordb Bulk Insert does not support --unix-socket-path option.
1 participant