Skip to content

Commit 96ff0f6

Browse files
authored
Merge branch 'master' into API_documentation
2 parents 9443ce6 + 92eba8d commit 96ff0f6

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ repository = "https://github.com/RedisGraph/redisgraph-py"
2525
[tool.poetry.dependencies]
2626
python = "^3.6"
2727
redis = "^3.5.3"
28+
hiredis = "^2.0.0"
2829
prettytable = "^2.1.0"
2930

3031
[tool.poetry.dev-dependencies]

redisgraph/graph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Graph:
1010
Graph, collection of nodes and edges.
1111
"""
1212

13-
def __init__(self, name, redis_con):
13+
def __init__(self, name, redis_con=None, host='localhost', port=6379, password=None):
1414
"""
1515
Create a new graph.
1616
@@ -19,7 +19,11 @@ def __init__(self, name, redis_con):
1919
redis_con: connection to Redis
2020
"""
2121
self.name = name # Graph key
22-
self.redis_con = redis_con
22+
if redis_con is not None:
23+
self.redis_con = redis_con
24+
else:
25+
self.redis_con = redis.Redis(host, port, password=password)
26+
2327
self.nodes = {}
2428
self.edges = []
2529
self._labels = [] # List of node labels.

redisgraph/util.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,4 @@ def quote_string(v):
2727

2828
v = v.replace('"', '\\"')
2929

30-
if v[0] != '"':
31-
v = '"' + v
32-
33-
if v[-1] != '"':
34-
v = v + '"'
35-
36-
return v
30+
return '"{}"'.format(v)

tests/functional/test_all.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def test_graph_creation(self):
4646
# All done, remove graph.
4747
redis_graph.delete()
4848

49+
def test_graph_connection(self):
50+
connections = len(self.r.client_list())
51+
redis_graph = Graph('social', self.r)
52+
del redis_graph
53+
self.assertTrue(self.r.ping())
54+
self.assertTrue(len(self.r.client_list()) == connections)
55+
56+
new_graph = Graph('social-new')
57+
self.assertTrue(new_graph.redis_con.ping())
58+
self.assertTrue(len(self.r.client_list()) == connections + 1)
59+
del new_graph
60+
self.assertTrue(len(self.r.client_list()) == connections)
61+
4962
def test_array_functions(self):
5063
redis_graph = Graph('social', self.r)
5164

tests/unit/test_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ def test_quote_string(self):
1414
self.assertEqual(util.quote_string(10), 10)
1515
self.assertEqual(util.quote_string("abc"), '"abc"')
1616
self.assertEqual(util.quote_string(""), '""')
17+
self.assertEqual(util.quote_string('\"'), '"\\\""')
18+
self.assertEqual(util.quote_string('"'), '"\\""')
1719
self.assertEqual(util.quote_string('a"a'), '"a\\"a"')

0 commit comments

Comments
 (0)