|  | @@ -1,3 +1,5 @@
 | 
	
		
			
				|  |  | +import traceback
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import redis
 | 
	
		
			
				|  |  |  import psycopg2
 | 
	
		
			
				|  |  |  from psycopg2 import pool as pgpool
 | 
	
	
		
			
				|  | @@ -5,10 +7,11 @@ from config import set_config
 | 
	
		
			
				|  |  |  from log import Log
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  config_ = set_config()
 | 
	
		
			
				|  |  | -log = Log()
 | 
	
		
			
				|  |  | +log_ = Log()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  conn_redis = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  class RedisHelper(object):
 | 
	
		
			
				|  |  |      def __init__(self):
 | 
	
		
			
				|  |  |          """
 | 
	
	
		
			
				|  | @@ -28,9 +31,9 @@ class RedisHelper(object):
 | 
	
		
			
				|  |  |          global conn_redis
 | 
	
		
			
				|  |  |          if conn_redis is None:
 | 
	
		
			
				|  |  |              pool = redis.ConnectionPool(host=self.host,
 | 
	
		
			
				|  |  | -                                    port=self.port,
 | 
	
		
			
				|  |  | -                                    password=self.password,
 | 
	
		
			
				|  |  | -                                    decode_responses=True)
 | 
	
		
			
				|  |  | +                                        port=self.port,
 | 
	
		
			
				|  |  | +                                        password=self.password,
 | 
	
		
			
				|  |  | +                                        decode_responses=True)
 | 
	
		
			
				|  |  |              conn = redis.Redis(connection_pool=pool)
 | 
	
		
			
				|  |  |              conn_redis = conn
 | 
	
		
			
				|  |  |          return conn_redis
 | 
	
	
		
			
				|  | @@ -231,7 +234,10 @@ class RedisHelper(object):
 | 
	
		
			
				|  |  |  #hologres_info = config_.HOLOGRES_INFO
 | 
	
		
			
				|  |  |  #conn = psycopg2.connect(**hologres_info)
 | 
	
		
			
				|  |  |  #cur = conn.cursor()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  connectPool = pgpool.SimpleConnectionPool(1, 10, **config_.HOLOGRES_INFO)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  class HologresHelper(object):
 | 
	
		
			
				|  |  |      def __init__(self):
 | 
	
		
			
				|  |  |          """初始化hologres连接信息"""
 | 
	
	
		
			
				|  | @@ -239,21 +245,26 @@ class HologresHelper(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def get_data(self, sql):
 | 
	
		
			
				|  |  |          #global conn
 | 
	
		
			
				|  |  | -        # 连接Hologres
 | 
	
		
			
				|  |  | -        #conn = psycopg2.connect(**self.hologres_info)
 | 
	
		
			
				|  |  | -        conn = connectPool.getconn()
 | 
	
		
			
				|  |  | -        # 创建游标
 | 
	
		
			
				|  |  | -        cur = conn.cursor()
 | 
	
		
			
				|  |  | -        # 查询数据
 | 
	
		
			
				|  |  | -        cur.execute(sql)
 | 
	
		
			
				|  |  | -        data = cur.fetchall()
 | 
	
		
			
				|  |  | -        cur.close()
 | 
	
		
			
				|  |  | -        connectPool.putconn(conn, close=False)
 | 
	
		
			
				|  |  | -        # 提交事务
 | 
	
		
			
				|  |  | -        #conn.commit()
 | 
	
		
			
				|  |  | -        # 释放资源
 | 
	
		
			
				|  |  | -        #cur.close()
 | 
	
		
			
				|  |  | -        #conn.close()
 | 
	
		
			
				|  |  | +        try:
 | 
	
		
			
				|  |  | +            # 连接Hologres
 | 
	
		
			
				|  |  | +            #conn = psycopg2.connect(**self.hologres_info)
 | 
	
		
			
				|  |  | +            conn = connectPool.getconn()
 | 
	
		
			
				|  |  | +            # 创建游标
 | 
	
		
			
				|  |  | +            cur = conn.cursor()
 | 
	
		
			
				|  |  | +            # 查询数据
 | 
	
		
			
				|  |  | +            cur.execute(sql)
 | 
	
		
			
				|  |  | +            data = cur.fetchall()
 | 
	
		
			
				|  |  | +            cur.close()
 | 
	
		
			
				|  |  | +            connectPool.putconn(conn, close=False)
 | 
	
		
			
				|  |  | +            # 提交事务
 | 
	
		
			
				|  |  | +            #conn.commit()
 | 
	
		
			
				|  |  | +            # 释放资源
 | 
	
		
			
				|  |  | +            #cur.close()
 | 
	
		
			
				|  |  | +            #conn.close()
 | 
	
		
			
				|  |  | +        except Exception as e:
 | 
	
		
			
				|  |  | +            log_.error('hologress error...')
 | 
	
		
			
				|  |  | +            log_.error(traceback.format_exc())
 | 
	
		
			
				|  |  | +            return []
 | 
	
		
			
				|  |  |          return data
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 |