Skip to content

Commit 75ab165

Browse files
authored
redis-py 4 (#85)
1 parent 2824c35 commit 75ab165

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisgraph-bulk-loader"
3-
version = "0.9.15"
3+
version = "0.10.0"
44
description = "RedisGraph Bulk Import Tool"
55
authors = ["Redis Inc <[email protected]>"]
66
license = "BSD-3-Clause"
@@ -30,7 +30,7 @@ repository = "https://github.com/RedisGraph/redisgraph-bulk-loader"
3030
[tool.poetry.dependencies]
3131
python = "^3.8.5"
3232
click = "^8.0.1"
33-
redis = "3.5.3"
33+
redis = "^4.1.4"
3434
pathos = "^0.2.8"
3535

3636
[tool.poetry.dev-dependencies]
@@ -42,7 +42,6 @@ bandit = "^1.7.0"
4242
vulture = "^2.3"
4343
pytest = "^6.2.4"
4444
pytest-cov = "^2.12.1"
45-
redisgraph = "^2.4.0"
4645
pathos = "^0.2.8"
4746

4847
[build-system]

redisgraph_bulk_loader/bulk_insert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def bulk_insert(graph, host, port, password, user, unix_socket_path, ssl_keyfile
120120

121121
# Attempt to verify that RedisGraph module is loaded
122122
try:
123-
module_list = client.execute_command("MODULE LIST")
124-
if not any(b'graph' in module_description for module_description in module_list):
123+
module_list = [m[b'name'] for m in client.module_list()]
124+
if b'graph' not in module_list:
125125
print("RedisGraph module not loaded on connected server.")
126126
sys.exit(1)
127127
except redis.exceptions.ResponseError:

redisgraph_bulk_loader/bulk_update.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import csv
33
import redis
44
import click
5-
from redisgraph import Graph
65
from timeit import default_timer as timer
76

87

@@ -28,7 +27,7 @@ def __init__(self, graph_name, max_token_size, separator, no_header, filename, q
2827
self.max_token_size = max_token_size * 1024 * 1024 - utf8len(self.query)
2928
self.filename = filename
3029
self.graph_name = graph_name
31-
self.graph = Graph(graph_name, client)
30+
self.graph = client.graph(graph_name)
3231
self.statistics = {}
3332

3433
def update_statistics(self, result):
@@ -136,8 +135,8 @@ def bulk_update(graph, host, port, password, user, unix_socket_path, query, vari
136135

137136
# Attempt to verify that RedisGraph module is loaded
138137
try:
139-
module_list = client.execute_command("MODULE LIST")
140-
if not any('graph' in module_description for module_description in module_list):
138+
module_list = [m['name'] for m in client.module_list()]
139+
if 'graph' not in module_list:
141140
print("RedisGraph module not loaded on connected server.")
142141
sys.exit(1)
143142
except redis.exceptions.ResponseError:

test/test_bulk_loader.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import csv
66
import redis
77
import unittest
8-
from redisgraph import Graph
8+
from redis import Redis
99
from click.testing import CliRunner
1010
from redisgraph_bulk_loader.bulk_insert import bulk_insert
1111

@@ -39,10 +39,13 @@ def setUpClass(cls):
3939
@classmethod
4040
def tearDownClass(cls):
4141
"""Delete temporary files"""
42-
os.remove('/tmp/nodes.tmp')
43-
os.remove('/tmp/relations.tmp')
44-
os.remove('/tmp/nodes_index.tmp')
45-
os.remove('/tmp/nodes_full_text_index.tmp')
42+
try:
43+
os.remove('/tmp/nodes.tmp')
44+
os.remove('/tmp/relations.tmp')
45+
os.remove('/tmp/nodes_index.tmp')
46+
os.remove('/tmp/nodes_full_text_index.tmp')
47+
except OSError:
48+
pass
4649
cls.redis_con.flushall()
4750

4851
def validate_exception(self, res, expected_msg):
@@ -89,7 +92,7 @@ def test01_social_graph(self):
8992
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)
9093

9194
# Open the constructed graph.
92-
graph = Graph('social', self.redis_con)
95+
graph = self.redis_con.graph('social')
9396
query_result = graph.query("MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name")
9497
# Verify that the Person label exists, has the correct attributes, and is properly populated.
9598
expected_result = [['Ailon Velger', 32, 'male', 'married'],
@@ -207,7 +210,7 @@ def test02_private_identifiers(self):
207210
self.assertIn('3 nodes created', res.output)
208211
self.assertIn('2 relations created', res.output)
209212

210-
tmp_graph = Graph(graphname, self.redis_con)
213+
tmp_graph = self.redis_con.graph(graphname)
211214
# The field "_identifier" should not be a property in the graph
212215
query_result = tmp_graph.query('MATCH (a) RETURN a')
213216

@@ -280,8 +283,8 @@ def test04_batched_build(self):
280283
self.assertIn(knows_count + " relations created for type 'KNOWS'", res.output)
281284
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)
282285

283-
original_graph = Graph('social', self.redis_con)
284-
new_graph = Graph(graphname, self.redis_con)
286+
original_graph = self.redis_con.graph('social')
287+
new_graph = self.redis_con.graph(graphname)
285288

286289
# Newly-created graph should be identical to graph created in single bulk command
287290
original_result = original_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
@@ -368,7 +371,7 @@ def test06_property_types(self):
368371
self.assertIn('3 nodes created', res.output)
369372
self.assertIn('3 relations created', res.output)
370373

371-
graph = Graph(graphname, self.redis_con)
374+
graph = self.redis_con.graph(graphname)
372375
query_result = graph.query('MATCH (a)-[e]->() RETURN a.numeric, a.mixed, a.bool, e.prop ORDER BY a.numeric, e.prop')
373376
expected_result = [[0.2, 'string_prop_1', True, True],
374377
[5, 'notnull', False, 3.5],
@@ -401,7 +404,7 @@ def test07_utf8(self):
401404
assert res.exit_code == 0
402405
assert '9 nodes created' in res.output
403406

404-
graph = Graph(graphname, self.redis_con)
407+
graph = self.redis_con.graph(graphname)
405408
# The non-ASCII property string must be escaped backticks to parse correctly
406409
query_result = graph.query("""MATCH (a) RETURN a.`utf8_str_ß` ORDER BY a.id""")
407410
expected_strs = [['Straße'],
@@ -439,7 +442,7 @@ def test08_nonstandard_separators(self):
439442
self.assertEqual(res.exit_code, 0)
440443
self.assertIn('2 nodes created', res.output)
441444

442-
graph = Graph(graphname, self.redis_con)
445+
graph = self.redis_con.graph(graphname)
443446
query_result = graph.query('MATCH (a) RETURN a.prop_a, a.prop_b, a.prop_c ORDER BY a.prop_a, a.prop_b, a.prop_c')
444447
expected_result = [['val1', 5, True],
445448
[10.5, 'a', False]]
@@ -465,7 +468,7 @@ def test09_schema(self):
465468
self.assertEqual(res.exit_code, 0)
466469
self.assertIn('2 nodes created', res.output)
467470

468-
graph = Graph(graphname, self.redis_con)
471+
graph = self.redis_con.graph(graphname)
469472
query_result = graph.query('MATCH (a) RETURN a.str_col, a.num_col, a.bool_col ORDER BY a.num_col')
470473
expected_result = [['0', 0, True],
471474
['1', 1, False]]
@@ -512,7 +515,7 @@ def test11_schema_ignore_columns(self):
512515
self.assertEqual(res.exit_code, 0)
513516
self.assertIn('2 nodes created', res.output)
514517

515-
graph = Graph(graphname, self.redis_con)
518+
graph = self.redis_con.graph(graphname)
516519
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')
517520

518521
# The nodes should only have the 'str_col' property
@@ -538,7 +541,7 @@ def test12_no_null_values(self):
538541
self.assertEqual(res.exit_code, 0)
539542
self.assertIn('2 nodes created', res.output)
540543

541-
graph = Graph(graphname, self.redis_con)
544+
graph = self.redis_con.graph(graphname)
542545
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')
543546

544547
# Only the first node should only have the 'mixed_col' property
@@ -580,7 +583,7 @@ def test13_id_namespaces(self):
580583
self.assertIn('4 nodes created', res.output)
581584
self.assertIn("2 relations created", res.output)
582585

583-
graph = Graph(graphname, self.redis_con)
586+
graph = self.redis_con.graph(graphname)
584587
query_result = graph.query('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id')
585588

586589
expected_result = [['0', 'Jeffrey', ['User'], '0', 20, ['Post']],
@@ -605,7 +608,7 @@ def test14_array_properties_inferred(self):
605608
self.assertEqual(res.exit_code, 0)
606609
self.assertIn('2 nodes created', res.output)
607610

608-
graph = Graph(graphname, self.redis_con)
611+
graph = self.redis_con.graph(graphname)
609612
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')
610613

611614
node_1 = {'str_col': 'str1', 'arr_col': [1, 0.2, 'nested_str', False]}
@@ -632,7 +635,7 @@ def test15_array_properties_schema_enforced(self):
632635
self.assertEqual(res.exit_code, 0)
633636
self.assertIn('2 nodes created', res.output)
634637

635-
graph = Graph(graphname, self.redis_con)
638+
graph = self.redis_con.graph(graphname)
636639
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')
637640

638641
node_1 = {'str_col': 'str1', 'arr_col': [1, 0.2, 'nested_str', False]}
@@ -707,7 +710,7 @@ def test18_ensure_full_text_index_is_created(self):
707710
self.assertIn('4 nodes created', res.output)
708711
self.assertIn('Indices created: 1', res.output)
709712

710-
graph = Graph(graphname, self.redis_con)
713+
graph = self.redis_con.graph(graphname)
711714
query_result = graph.query("CALL db.idx.fulltext.queryNodes('Monkeys', 'tamarin') YIELD node RETURN node.name")
712715
expected_result = [['Emperor Tamarin'], ['Golden Lion Tamarin'], ['Cotton-top Tamarin']]
713716

@@ -748,7 +751,7 @@ def test19_integer_ids(self):
748751
self.assertIn('4 nodes created', res.output)
749752
self.assertIn("2 relations created", res.output)
750753

751-
graph = Graph(graphname, self.redis_con)
754+
graph = self.redis_con.graph(graphname)
752755
query_result = graph.query('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id')
753756

754757
# The IDs of the results should be parsed as integers

test/test_bulk_update.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import csv
55
import redis
66
import unittest
7-
from redisgraph import Graph
7+
from redis import Redis
88
from click.testing import CliRunner
99
from redisgraph_bulk_loader.bulk_update import bulk_update
1010

@@ -45,7 +45,7 @@ def test01_simple_updates(self):
4545
self.assertIn('Nodes created: 3', res.output)
4646
self.assertIn('Properties set: 6', res.output)
4747

48-
tmp_graph = Graph(graphname, self.redis_con)
48+
tmp_graph = self.redis_con.graph(graphname)
4949
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')
5050

5151
# Validate that the expected results are all present in the graph
@@ -88,7 +88,7 @@ def test02_traversal_updates(self):
8888
self.assertIn('Relationships created: 3', res.output)
8989
self.assertIn('Properties set: 6', res.output)
9090

91-
tmp_graph = Graph(graphname, self.redis_con)
91+
tmp_graph = self.redis_con.graph(graphname)
9292
query_result = tmp_graph.query('MATCH (a)-[:R]->(b) RETURN a.name, b.name ORDER BY a.name, b.name')
9393

9494
# Validate that the expected results are all present in the graph
@@ -115,7 +115,7 @@ def test03_datatypes(self):
115115
self.assertIn('Nodes created: 1', res.output)
116116
self.assertIn('Properties set: 5', res.output)
117117

118-
tmp_graph = Graph(graphname, self.redis_con)
118+
tmp_graph = self.redis_con.graph(graphname)
119119
query_result = tmp_graph.query('MATCH (a) RETURN a.intval, a.doubleval, a.boolval, a.stringval, a.arrayval')
120120

121121
# Validate that the expected results are all present in the graph
@@ -144,7 +144,7 @@ def test04_custom_delimiter(self):
144144
self.assertIn('Nodes created: 3', res.output)
145145
self.assertIn('Properties set: 6', res.output)
146146

147-
tmp_graph = Graph(graphname, self.redis_con)
147+
tmp_graph = self.redis_con.graph(graphname)
148148
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')
149149

150150
# Validate that the expected results are all present in the graph
@@ -183,7 +183,7 @@ def test05_custom_variable_name(self):
183183
self.assertIn('Nodes created: 14', res.output)
184184
self.assertIn('Properties set: 56', res.output)
185185

186-
tmp_graph = Graph(graphname, self.redis_con)
186+
tmp_graph = self.redis_con.graph(graphname)
187187

188188
# Validate that the expected results are all present in the graph
189189
query_result = tmp_graph.query('MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name')
@@ -224,7 +224,7 @@ def test06_no_header(self):
224224
self.assertIn('Nodes created: 3', res.output)
225225
self.assertIn('Properties set: 6', res.output)
226226

227-
tmp_graph = Graph(graphname, self.redis_con)
227+
tmp_graph = self.redis_con.graph(graphname)
228228
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')
229229

230230
# Validate that the expected results are all present in the graph
@@ -256,7 +256,7 @@ def test07_batched_update(self):
256256
self.assertIn('Nodes created: 100000', res.output)
257257
self.assertIn('Properties set: 100000', res.output)
258258

259-
tmp_graph = Graph(graphname, self.redis_con)
259+
tmp_graph = self.redis_con.graph(graphname)
260260
query_result = tmp_graph.query('MATCH (a) RETURN DISTINCT a.prop')
261261

262262
# Validate that the expected results are all present in the graph

0 commit comments

Comments
 (0)