-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request involve the Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
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 theFalkorDB
class by allowing connections via Unix sockets.Key points:
- The change correctly adds
unix_socket_path
to thekwargs
dictionary.- It uses the appropriate key ("path") from
connection_kwargs
.- The implementation is consistent with Redis's handling of Unix socket connections.
To ensure a robust implementation:
- Verify full Unix socket support throughout the class (see the verification script in a previous comment).
- Add specific unit tests for Unix socket connections.
- Update documentation to reflect the new functionality.
- 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
tokwargs
is correct and aligns with the PR objective of supporting Unix socket connections. This change should allow theFalkorDB
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 theFalkorDB
class and related files.Verification successful
Verified! Unix socket support is correctly implemented.
The
unix_socket_path
is properly set and utilized within both theFalkorDB
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") |
There was a problem hiding this comment.
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:
- Add unit tests specifically for Unix socket connections using the
from_url
method. - Update the class and method docstrings to mention Unix socket support.
- 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
This should fix FalkorDB/falkordb-bulk-loader#11.
Summary by CodeRabbit
from_url
method for establishing connections.