1
2
3
4
5
6
7
8
9
10 import redis
11 import re
12
13
14
15
16
17
19 '''
20 Root the specified redis key name in our pseudo redis database.
21 '''
22 if re.match('rocon:', key):
23 return key
24 else:
25 return 'rocon:' + key
26
27
29 '''
30 Root the specified redis key name in our pseudo redis database under
31 the hub namespace
32 '''
33 if re.match('rocon:hub:', key):
34 return key
35 else:
36 return 'rocon:hub:' + key
37
38
40 '''
41 Root the specified redis key name in our pseudo redis database under
42 the gateway namespace.
43
44 @note : currently does no checking of the incoming keys
45 '''
46 return 'rocon:' + unique_gateway_name + ":" + key
47
48
50 '''
51 Extract the specified redis key name from our pseudo redis database.
52 '''
53 if re.match('rocon:', key):
54 return re.sub(r'rocon:', '', key)
55 else:
56 return key
57
58
60 '''
61 Extract the base name (i.e. last value) from the key.
62 e.g. rocon:key:pirate24 -> pirate24
63 '''
64 return key.split(':')[-1]
65
66
68 '''
69 Pings the hub for identification. This is currently used
70 by the hub discovery module.
71
72 @return Bool
73 '''
74 try:
75 r = redis.Redis(host=ip, port=port)
76 name = r.get("rocon:hub:name")
77 except redis.exceptions.ConnectionError:
78 return False
79 if name is None:
80 return False
81 return True
82