-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontstructor.py
47 lines (33 loc) · 1.12 KB
/
contstructor.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import redis
from datetime import datetime
from json import dumps,loads
class queue():
def __init__(self):
self.connection = redis.StrictRedis(host='localhost',port=6379, db=0)
def currentTime(self):
datetimeOBJ = datetime.now()
timestamp = datetimeOBJ.strftime("%d-%b-%Y %H:%M:%S")
return timestamp
def setExpire(self):
self.connection.expire("dataLidar",86400)
def pushQueue(self, data):
try:
push_to_queue = self.connection.rpush("dataLidar", dumps({"timestamp":self.currentTime(),"data":data}))
self.setExpire()
return True
except:
return False
def FifoPopQueue(self):
try:
pop_from_queue = self.connection.rpop("dataLidar")
pop_from_queue = loads(pop_from_queue)
return pop_from_queue
except:
return None
def LifoPopQueue(self):
try:
pop_from_queue = self.connection.lpop("dataLidar")
pop_from_queue = loads(pop_from_queue)
return pop_from_queue
except:
return None