-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.py
28 lines (22 loc) · 873 Bytes
/
meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import redis
from redisgraph import Node, Edge, Graph
import settings as st
r = redis.Redis(host=st.meta_server, port=st.meta_port)
redis_graph = Graph('chunks', r)
def create_file_meta(file_name, graph_obj=redis_graph):
this_file = Node(label='file', properties={'name': file_name})
graph_obj.add_node(this_file)
return this_file
def create_chunk_node(chunk_hash, chunk_seq, chunk_len, file_obj):
this_cnk = Node(label='chunk',
properties={
'hash': chunk_hash,
'length': chunk_len
})
redis_graph.add_node(this_cnk)
this_edge = Edge(file_obj,
'has_chunk',
this_cnk,
properties={'seq': chunk_seq})
redis_graph.add_edge(this_edge)
return this_cnk, this_edge