Skip to content

Fix: Support unix socket connection to Redis#66

Open
sachinjogi wants to merge 6 commits intoFalkorDB:mainfrom
sachinjogi:patch-1
Open

Fix: Support unix socket connection to Redis#66
sachinjogi wants to merge 6 commits intoFalkorDB:mainfrom
sachinjogi:patch-1

Conversation

@sachinjogi
Copy link

@sachinjogi sachinjogi commented Sep 24, 2024

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

Summary by CodeRabbit

  • New Features
    • Connection flexibility improved: the library now supports establishing connections using a Unix domain socket path supplied in connection URLs, making local socket-based setups easier to use. This enhancement preserves existing public APIs and requires no changes to how consumers call the library.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

FalkorDB.from_url now propagates a Unix domain socket path into the Redis connection kwargs by assigning kwargs["unix_socket_path"] from the parsed connection path. No public API signature changes; Unix socket URLs are now honored.

Changes

Cohort / File(s) Summary
Core connection logic
falkordb/falkordb.py
In FalkorDB.from_url, extract the parsed path and set kwargs["unix_socket_path"] = connection_kwargs.get("path") before SSL handling so Unix socket URLs are passed to the downstream Redis client.
sequenceDiagram
    autonumber
    participant Client
    participant FalkorDB as FalkorDB.from_url
    participant RedisLib as redis.from_url
    participant RedisSock as UnixSocket/Redis

    Client->>FalkorDB: call from_url("unix:///sockets/redis0.sock", ...)
    FalkorDB->>FalkorDB: parse URL -> connection_kwargs (path="/sockets/redis0.sock")
    FalkorDB->>FalkorDB: set kwargs["unix_socket_path"] = connection_kwargs.get("path")
    FalkorDB->>RedisLib: call redis.from_url(..., unix_socket_path="/sockets/redis0.sock")
    RedisLib->>RedisSock: open unix socket "/sockets/redis0.sock"
    RedisSock-->>RedisLib: accept connection
    RedisLib-->>FalkorDB: connection established
    FalkorDB-->>Client: return client instance
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

"I hop with a socket tucked snug in my pack,
Pipes of the kernel trace my quick track.
From URL I fetch the path, snug and neat,
Unix hops replace TCP's old beat.
Happy rabbit, connection complete! 🐇"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for Unix socket connections to Redis in FalkorDB, which directly addresses the pull request's primary objective.
Linked Issues check ✅ Passed The code change propagates the Unix socket path from connection_kwargs to enable Unix socket connections, directly addressing issue #11's requirement for Unix socket support in falkordb-bulk-insert.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to Unix socket path propagation in FalkorDB.from_url, directly addressing the linked issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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

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
Contributor

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

@sachinjogi
Copy link
Author

@gkorland can you please review this when you're free?

@gkorland gkorland requested a review from swilly22 June 21, 2025 18:44
Copy link
Contributor

@swilly22 swilly22 left a comment

Choose a reason for hiding this comment

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

Please add documentation & tests

@gkorland
Copy link
Contributor

Please add documentation & tests

@copilot can you please help here?

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.45%. Comparing base (fe85af5) to head (3705fb2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #66   +/-   ##
=======================================
  Coverage   90.45%   90.45%           
=======================================
  Files          36       36           
  Lines        2776     2777    +1     
=======================================
+ Hits         2511     2512    +1     
  Misses        265      265           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
falkordb/falkordb.py (1)

173-173: Conditionally assign host/port when not using Unix socket connections.

When from_url() parses a unix:// URL, it correctly extracts the socket path to connection_kwargs["path"], but the current implementation unconditionally sets host and port to defaults (lines 169-170). This results in passing redundant host/port values to FalkorDB.__init__() when a Unix socket is being used.

Since redis-py uses the "path" key in connection_kwargs to store the Unix socket path, you can conditionally set host/port only for TCP connections:

 connection_kwargs = conn.connection_pool.connection_kwargs
 connection_class = conn.connection_pool.connection_class
-kwargs["host"] = connection_kwargs.get("host", "localhost")
-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")
+
+# Only set host/port for non-Unix socket connections
+if kwargs["unix_socket_path"] is None:
+    kwargs["host"] = connection_kwargs.get("host", "localhost")
+    kwargs["port"] = connection_kwargs.get("port", 6379)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7204de and 3705fb2.

📒 Files selected for processing (1)
  • falkordb/falkordb.py

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for connecting to Redis via Unix domain sockets by correctly mapping the socket path from Redis connection parameters to FalkorDB's initialization. The fix addresses issue #11 in the falkordb-bulk-loader project.

Changes:

  • Extracts unix socket path from Redis connection pool parameters and passes it to FalkorDB initialization
  • Enables from_url() method to support unix:// URLs in addition to existing falkor:// and falkors:// schemes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kwargs["username"] = connection_kwargs.get("username")
kwargs["password"] = connection_kwargs.get("password")
kwargs["unix_socket_path"] = connection_kwargs.get("path")

Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Remove trailing whitespace from this line.

Suggested change

Copilot uses AI. Check for mistakes.
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

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Consider adding test coverage for unix socket connections. The existing tests in tests/test_db.py::test_connect_via_url only cover TCP connections (falkor:// scheme). Adding a test case for unix:// URLs would help ensure this feature works correctly and prevent regressions.

Copilot uses AI. Check for mistakes.
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.

4 participants