Пример #1
0
def getEventLog(db,conn,e_type,playerId):
    #先从cache中获取
    info = memory_cache.getAuctionEventLogCache(playerId)
    if info:
        return info
        
    db.execute("SELECT * FROM event_log WHERE type = %s AND user_id = %s order by create_time desc limit 16",(e_type,playerId))
    info = []
    try:
        logs = db.fetchall()
        '''
        #删除过期数据
        if len(logs) > 16:
            #evengLog = logs[15]
            evengLog = logs.pop()
            db.execute("delete from event_log where user_id = %s and create_time < %s",(evengLog['user_id'],evengLog['create_time']))
            conn.commit()
        '''
    except:
        return info
    for log in logs:
        temp = __auctionStringToDict(log['info'])
        temp['time'] = log['create_time']
        info.append(temp)
    
    #set cache
    memory_cache.setAuctionEventLogCache(playerId,info)
    
    return info
Пример #2
0
def writeEventLog(db,conn,log_info,playerId):
    time_now = int(time.time())
    log_str = __dictToString(log_info)
    db.execute("INSERT INTO event_log(type,user_id,info,create_time) VALUES(%s,%s,%s,%s)",(1,playerId,log_str,time_now))
    conn.commit()
    
    #clear cache
    memory_cache.setAuctionEventLogCache(playerId,None)