Skip to content

Commit c6248f6

Browse files
authored
Removing connection options in favour of redis-url (#97)
1 parent de4d4b5 commit c6248f6

File tree

3 files changed

+9
-66
lines changed

3 files changed

+9
-66
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ python3 redisgraph_bulk_loader/bulk_insert.py GRAPHNAME [OPTIONS]
3939

4040
| Flags | Extended flags | Parameter |
4141
|:-----:|----------------------------|:----------------------------------------------------------------------------------------------------:|
42-
| -h | --host TEXT | Redis server host (default: 127.0.0.1) |
43-
| -p | --port INTEGER | Redis server port (default: 6379) |
44-
| -a | --password TEXT | Redis server password (default: none) |
45-
| -u | --unix-socket-path TEXT | Redis unix socket path (default: none) |
46-
| -k | --ssl-keyfile TEXT | Path to SSL keyfile (default: none) |
47-
| -l | --ssl-certfile TEXT | Path to SSL certfile (default: none) |
48-
| -m | --ssl-ca-certs TEXT | Path to SSL CA certs (default: none) |
42+
| -u | --redis-url TEXT | Redis url (default: redis://127.0.0.1:6379) |
4943
| -n | --nodes TEXT | Path to Node CSV file with the filename as the Node Label |
5044
| -N | --nodes-with-label TEXT | Node Label followed by path to Node CSV file |
5145
| -r | --relations TEXT | Path to Relationship CSV file with the filename as the Relationship Type |

redisgraph_bulk_loader/bulk_insert.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ssl
21
import sys
32
from timeit import default_timer as timer
43

@@ -51,17 +50,9 @@ def process_entities(entities):
5150
@click.command()
5251
@click.argument("graph")
5352
# Redis server connection settings
54-
@click.option("--host", "-h", default="127.0.0.1", help="Redis server host")
55-
@click.option("--port", "-p", default=6379, help="Redis server port")
56-
@click.option("--password", "-a", default=None, help="Redis server password")
57-
@click.option("--user", "-w", default=None, help="Username for Redis ACL")
5853
@click.option(
59-
"--unix-socket-path", "-u", default=None, help="Redis server unix socket path"
54+
"--redis-url", "-u", default="redis://127.0.0.1:6379", help="Redis connection url"
6055
)
61-
@click.option("--ssl-keyfile", "-k", default=None, help="SSL keyfile")
62-
@click.option("--ssl-certfile", "-l", default=None, help="SSL certfile")
63-
@click.option("--ssl-ca-certs", "-m", default=None, help="SSL CA certs")
64-
# CSV file paths
6556
@click.option("--nodes", "-n", multiple=True, help="Path to node csv file")
6657
@click.option(
6758
"--nodes-with-label",
@@ -151,14 +142,7 @@ def process_entities(entities):
151142
)
152143
def bulk_insert(
153144
graph,
154-
host,
155-
port,
156-
password,
157-
user,
158-
unix_socket_path,
159-
ssl_keyfile,
160-
ssl_certfile,
161-
ssl_ca_certs,
145+
redis_url,
162146
nodes,
163147
nodes_with_label,
164148
relations,
@@ -202,25 +186,11 @@ def bulk_insert(
202186
escapechar,
203187
)
204188

205-
kwargs = {"host": host, "port": port, "username": user, "password": password}
206-
207-
if unix_socket_path is not None:
208-
kwargs.update({"unix_socket_path": unix_socket_path})
209-
210-
if ssl_keyfile or ssl_certfile or ssl_ca_certs:
211-
kwargs.update(
212-
{
213-
"ssl": True,
214-
"ssl_keyfile": ssl_keyfile,
215-
"ssl_certfile": ssl_certfile,
216-
"ssl_cert_reqs": ssl.CERT_REQUIRED,
217-
"ssl_ca_certs": ssl_ca_certs,
218-
}
219-
)
189+
client = redis.from_url(redis_url)
220190

221191
# Attempt to connect to Redis server
222192
try:
223-
client = redis.Redis(**kwargs)
193+
client.ping()
224194
except redis.exceptions.ConnectionError as e:
225195
print("Could not connect to Redis server.")
226196
raise e

redisgraph_bulk_loader/bulk_update.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ def process_update_csv(self):
129129
@click.command()
130130
@click.argument("graph")
131131
# Redis server connection settings
132-
@click.option("--host", "-h", default="127.0.0.1", help="Redis server host")
133-
@click.option("--port", "-p", default=6379, help="Redis server port")
134-
@click.option("--password", "-a", default=None, help="Redis server password")
135-
@click.option("--user", "-w", default=None, help="Username for Redis ACL")
136132
@click.option(
137-
"--unix-socket-path", "-u", default=None, help="Redis server unix socket path"
133+
"--redis-url", "-u", default="redis://127.0.0.1:6379", help="Redis connection url"
138134
)
139135
# Cypher query options
140136
@click.option("--query", "-q", help="Query to run on server")
@@ -165,11 +161,7 @@ def process_update_csv(self):
165161
)
166162
def bulk_update(
167163
graph,
168-
host,
169-
port,
170-
password,
171-
user,
172-
unix_socket_path,
164+
redis_url,
173165
query,
174166
variable_name,
175167
csv,
@@ -183,22 +175,9 @@ def bulk_update(
183175
start_time = timer()
184176

185177
# Attempt to connect to Redis server
178+
client = redis.from_url(redis_url, decode_responses=True)
186179
try:
187-
if unix_socket_path is not None:
188-
client = redis.StrictRedis(
189-
unix_socket_path=unix_socket_path,
190-
username=user,
191-
password=password,
192-
decode_responses=True,
193-
)
194-
else:
195-
client = redis.StrictRedis(
196-
host=host,
197-
port=port,
198-
username=user,
199-
password=password,
200-
decode_responses=True,
201-
)
180+
client.ping()
202181
except redis.exceptions.ConnectionError as e:
203182
print("Could not connect to Redis server.")
204183
raise e

0 commit comments

Comments
 (0)