-
Notifications
You must be signed in to change notification settings - Fork 2
/
InventoryObj.py
58 lines (50 loc) · 1.85 KB
/
InventoryObj.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
48
49
50
51
52
53
54
55
56
57
58
debug=True
from Object import Object
class InventoryObj(Object):
def __init__(self):
self.sql="""
SELECT B.Owner, A.ShopID,A.CommodityID,B.CRefID,A.HadNumber,A.MaxNumber,B.ShopName,C.CName,C.BasePrice FROM RShopWareRoom A
LEFT JOIN GShopStore B ON A.ShopID=B.ShopID LEFT JOIN GCommodity C ON A.CommodityID=C.CommodityID
LEFT JOIN CCityPositionRef D ON B.CRefID=D.CRefID
"""
def write2Redis(self):
self.getDataFromDB()
indexOfOwner = -1
indexOfShopID = -1
indexOfCommodityID = -1
for i in range(len(self.head)):
if(self.head[i]=="Owner"):
indexOfOwner=i
break
if(indexOfOwner == -1):
return False
for i in range(len(self.head)):
if(self.head[i]=="ShopID"):
indexOfShopID=i
break
if(indexOfShopID == -1):
return False
for i in range(len(self.head)):
if(self.head[i]=="CommodityID"):
indexOfCommodityID=i
break
if(indexOfCommodityID == -1):
return False
for iLine in self.results:
objID="player:"+str(iLine[indexOfOwner])
objID=objID+":store:"+str(iLine[indexOfShopID])
objID=objID+":inventoryObj:"+str(iLine[indexOfCommodityID])
command="hMSet "+objID+" "
for i in range(len(self.head)):
command = command + self.head[i]+" "+str(iLine[i])+" "
from exeRedis import Redis
redis = Redis()
redis.exe(command)
if(debug):
print command
print "===================================================="
return True
#test
if(__name__=="__main__"):
test= InventoryObj()
print test.write2Redis()