欢迎投稿

今日深度:

python--Hbase插入数据,python--hbase插入

python--Hbase插入数据,python--hbase插入


#coding=utf-8
import happybase

port = xxxxxx
host = xxxxxx

class HbaseConPool(object):
    '''hbase连接池'''
    def __init__(self):
        '''
        Constructor
        '''
        self.pool = happybase.ConnectionPool(size=20,host=xxx,port=xxx,timeout=60000*2)

    def __new__(cls,*args,**kwargs):
        '''   
        '''
        if not hasattr(cls,'_inst'):
            cls._inst=super(HbaseConPool,cls).__new__(cls,*args,**kwargs)
        return cls._inst
    
#     def createHbaseConPool(self):
#         pool = happybase.ConnectionPool(5,host=constant.HBASE_HOST,port=constant.HBASE_PORT)
            
    def get_conn(self):
        '''从hbase连接池中获得一个hbase链接'''
#         if self.pool == None:
#             self.pool = self.createHbaseConPool()
        return self.pool.connection()
    
    def close(self):
        '''关闭hbase连接池'''
        self.pool.connection.close()


#     def __exit__(self):
#         print '=============='
#         self.pool.connection.close()
    
    
hbase_con_pool = HbaseConPool()


if __name__ == '__main__':
    with hbase_con_pool.get_conn() as conn:
#         batch = conn.batch('zx')
#         table = conn.table('zx')
# #         batch = table.batch()
# #         batch = batch.put('002',{'cf1:age':'22'})
# #         batch = batch.put('002',{'cf1:match':'138'})
# #         batch.send()
#         table.put('002',{'cf1:age':'22'})
#         table.put('002',{'cf1:match':'138'})
#         rs = table.scan()
#         for key,data in rs:
#             print key,data

#设置睡眠百分比(Row:用户id+设备id)
        table = conn.table('sleep_status_count')
        table.put('000005Z04U0UQB0OJM4V1',
                  {'cf:deviceId': '', 
                   'cf:sleepStatusCount': '',
                   'cf:userId': ''
                   })
        rs = table.row('000005Z04U0UQB0OJM4V1')
        print rs

www.htsjk.Com true http://www.htsjk.com/hbase/34702.html NewsArticle python--Hbase插入数据,python--hbase插入 #coding=utf-8 import happybase port = xxxxxx host = xxxxxx class HbaseConPool(object):     '''hbase连接池'''     def __init__(self):         '''         Constructor        ...
相关文章
    暂无相关文章
评论暂时关闭