Skip to content

Removing connection options in favour of redis-url #97

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
Jul 19, 2022
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
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ python3 redisgraph_bulk_loader/bulk_insert.py GRAPHNAME [OPTIONS]

| Flags | Extended flags | Parameter |
|:-----:|----------------------------|:----------------------------------------------------------------------------------------------------:|
| -h | --host TEXT | Redis server host (default: 127.0.0.1) |
| -p | --port INTEGER | Redis server port (default: 6379) |
| -a | --password TEXT | Redis server password (default: none) |
| -u | --unix-socket-path TEXT | Redis unix socket path (default: none) |
| -k | --ssl-keyfile TEXT | Path to SSL keyfile (default: none) |
| -l | --ssl-certfile TEXT | Path to SSL certfile (default: none) |
| -m | --ssl-ca-certs TEXT | Path to SSL CA certs (default: none) |
| -u | --redis-url TEXT | Redis url (default: redis://127.0.0.1:6379) |
| -n | --nodes TEXT | Path to Node CSV file with the filename as the Node Label |
| -N | --nodes-with-label TEXT | Node Label followed by path to Node CSV file |
| -r | --relations TEXT | Path to Relationship CSV file with the filename as the Relationship Type |
Expand Down
38 changes: 4 additions & 34 deletions redisgraph_bulk_loader/bulk_insert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ssl
import sys
from timeit import default_timer as timer

Expand Down Expand Up @@ -51,17 +50,9 @@ def process_entities(entities):
@click.command()
@click.argument("graph")
# Redis server connection settings
@click.option("--host", "-h", default="127.0.0.1", help="Redis server host")
@click.option("--port", "-p", default=6379, help="Redis server port")
@click.option("--password", "-a", default=None, help="Redis server password")
@click.option("--user", "-w", default=None, help="Username for Redis ACL")
@click.option(
"--unix-socket-path", "-u", default=None, help="Redis server unix socket path"
"--redis-url", "-u", default="redis://127.0.0.1:6379", help="Redis connection url"
)
@click.option("--ssl-keyfile", "-k", default=None, help="SSL keyfile")
@click.option("--ssl-certfile", "-l", default=None, help="SSL certfile")
@click.option("--ssl-ca-certs", "-m", default=None, help="SSL CA certs")
# CSV file paths
@click.option("--nodes", "-n", multiple=True, help="Path to node csv file")
@click.option(
"--nodes-with-label",
Expand Down Expand Up @@ -151,14 +142,7 @@ def process_entities(entities):
)
def bulk_insert(
graph,
host,
port,
password,
user,
unix_socket_path,
ssl_keyfile,
ssl_certfile,
ssl_ca_certs,
redis_url,
nodes,
nodes_with_label,
relations,
Expand Down Expand Up @@ -202,25 +186,11 @@ def bulk_insert(
escapechar,
)

kwargs = {"host": host, "port": port, "username": user, "password": password}

if unix_socket_path is not None:
kwargs.update({"unix_socket_path": unix_socket_path})

if ssl_keyfile or ssl_certfile or ssl_ca_certs:
kwargs.update(
{
"ssl": True,
"ssl_keyfile": ssl_keyfile,
"ssl_certfile": ssl_certfile,
"ssl_cert_reqs": ssl.CERT_REQUIRED,
"ssl_ca_certs": ssl_ca_certs,
}
)
client = redis.from_url(redis_url)

# Attempt to connect to Redis server
try:
client = redis.Redis(**kwargs)
client.ping()
except redis.exceptions.ConnectionError as e:
print("Could not connect to Redis server.")
raise e
Expand Down
29 changes: 4 additions & 25 deletions redisgraph_bulk_loader/bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ def process_update_csv(self):
@click.command()
@click.argument("graph")
# Redis server connection settings
@click.option("--host", "-h", default="127.0.0.1", help="Redis server host")
@click.option("--port", "-p", default=6379, help="Redis server port")
@click.option("--password", "-a", default=None, help="Redis server password")
@click.option("--user", "-w", default=None, help="Username for Redis ACL")
@click.option(
"--unix-socket-path", "-u", default=None, help="Redis server unix socket path"
"--redis-url", "-u", default="redis://127.0.0.1:6379", help="Redis connection url"
)
# Cypher query options
@click.option("--query", "-q", help="Query to run on server")
Expand Down Expand Up @@ -165,11 +161,7 @@ def process_update_csv(self):
)
def bulk_update(
graph,
host,
port,
password,
user,
unix_socket_path,
redis_url,
query,
variable_name,
csv,
Expand All @@ -183,22 +175,9 @@ def bulk_update(
start_time = timer()

# Attempt to connect to Redis server
client = redis.from_url(redis_url, decode_responses=True)
try:
if unix_socket_path is not None:
client = redis.StrictRedis(
unix_socket_path=unix_socket_path,
username=user,
password=password,
decode_responses=True,
)
else:
client = redis.StrictRedis(
host=host,
port=port,
username=user,
password=password,
decode_responses=True,
)
client.ping()
except redis.exceptions.ConnectionError as e:
print("Could not connect to Redis server.")
raise e
Expand Down