コード例 #1
0
 def zRangeRemByScore(key, _min=0, _max=None):
     if _max == None: _max = TMSL()
     if MyRedis.redis_status:
         try:
             lines = MyRedis.rs.zrangebyscore(key, _min, _max)
             MyRedis.rs.zremrangebyscore(key, _min, _max)
             return [eval(line) for line in lines]
         except:
             L.error('zrangeRemByScore error', key)
     return []
コード例 #2
0
    def run(self, sql):
        cnx = self.getConnection()
        cursor = cnx.cursor()

        emp_no = 0
        try:
            cursor.execute(sql)
            emp_no = cursor.lastrowid
            cnx.commit()
        except Exception as e:
            emp_no = -1
            L.error("Run Error: " + sql)
            L.error(e)
        '''End Try'''
        cursor.close()
        cnx.close()
        return emp_no
コード例 #3
0
def detection_data_citys():
    db = Database()
    unknowns = {}    
    sql = '''SELECT region_parent, region_name FROM patients WHERE region_level=2 
        group by region_parent, region_name'''
    for (parent, name) in db.select(sql):
        if parent not in REGIONS:
            L.error("Not in Region Source: {}".format(parent))
            continue
        if check_city(name, parent): continue
        
        if parent not in unknowns: unknowns[parent] = set()
        unknowns[parent].add(name)

    for p in unknowns:
        print('----------------------')
        print([v['name'] for v in REGIONS[p]['children'].values()])
        print(list(unknowns[p]))
コード例 #4
0
 def getConnection(self):
     '''检查是否初始化'''
     if not Database.pool:
         Database.pool = PooledDB(mysql.connector,
                                  cfg.POOL_SIZE,
                                  host=cfg.HOST,
                                  port=cfg.PORT,
                                  user=cfg.USER_NAME,
                                  passwd=cfg.PASSWORD,
                                  db=cfg.DB_NAME,
                                  use_unicode=True,
                                  charset='utf8')
     cnx = None
     try:
         cnx = Database.pool.connection()
         self.lsConn.append(cnx)
     except:
         L.error('pool error:' + str(len(self.lsConn)))
     return cnx
コード例 #5
0
    def Transaction(self, lines, cnx=None, cursor=None):
        if cnx == None: cnx = self.getConnection()
        if cursor == None:
            cursor = cnx.cursor()
            self.lsCurs.append(cursor)
        flag, lsRst = True, []
        '''开启事务'''
        cursor.execute("BEGIN;")
        try:
            for line in lines:
                cursor.execute(line[0], line[1])
                lsRst.append(cursor.lastrowid)
            cnx.commit()
        except Error as e:
            cnx.rollback()
            flag = False
            L.error('Error: ' + str(e))
        '''End For'''

        cursor.close()
        cnx.close()
        return flag, lsRst
コード例 #6
0
 def zadd(key, value, score):
     # 暂时不支持本地模式
     MyRedis.checkConn()
     if MyRedis.redis_status:
         try:
             if MyRedis.rs.zcard(key) < MyRedis.ZMaxCount:
                 return MyRedis.rs.zadd(key, value, score)
             else:
                 return L.error(
                     'Collection size is too big over ZMaxCount when zadd')
         except:
             MyRedis.SwitchToLocal()
     if key not in MyRedis.dataHash: MyRedis.dataHash[key] = {}
     MyRedis.dataHash[key][score] = value
     return False
コード例 #7
0
 def SwitchToLocal():
     raise RuntimeError('Redis Error')
     if not C.DEV_MODE: return
     MyRedis.redis_status = False
     L.error("RedisEx find error in Function: " + inspect.stack()[1][3])