sqlserver同步到redis_SQLServer数据库之redis数据库的数据导入到SQLServer数据库中
本文主要向大家介绍了SQLServer数据库之redis数据库的数据导入到SQLServer数据库中,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。#!/usr/bin/python#-*-coding:utf-8-*-"""@author:yugengde@contact:yugengde@163.com@file:redis_sqlserver.py@t...
本文主要向大家介绍了SQLServer数据库之redis数据库的数据导入到SQLServer数据库中,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
#!/usr/bin/python# -*-coding:utf-8-*- """@author: yugengde@contact: yugengde@163.com@file : redis_sqlserver.py@time: 2017/11/11 16:50"""import redisimport pymssqlimport jsonfrom multiprocessing import PoolMSSQL_URL = ‘**.**.**.**‘MSSQL_USER = ‘sa‘MSSQL_PASSWD = ‘****‘MSSQL_DB = ‘amazon‘MSSQL_CHARSET = ‘utf8‘r = redis.Redis(host=‘**.**.**.**‘,password=‘******‘)def insert_sqlserver(item): # print(‘start insert...‘) item = json.loads(item) conn = pymssql.connect(host=MSSQL_URL,user=MSSQL_USER,password=MSSQL_PASSWD,database=MSSQL_DB,charset=MSSQL_CHARSET) cursor = conn.cursor() # 数据库插入 sql = "insert into amazon(\ title,brand,classify,sku,price,\ comment_num,comment_av,product_attr,promotion,product_desc,\ product_info,url,save_time,hash_value\ ) VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s,%s, %s,%s,%s,%s)" try: cursor.execute(sql, (item[‘title‘],item[‘brand‘],item[‘classify‘],item[‘sku‘],item[‘price‘], \ item[‘comment_num‘],item[‘comment_av‘],item[‘product_attr‘],item[‘promotion‘],item[‘product_desc‘], \ item[‘product_info‘],item[‘url‘],item[‘save_time‘],item[‘hash_value‘],)) conn.commit() # print(‘==================================================================‘) # print(‘数据存储成功‘, item) # print(‘==================================================================‘) except: print(‘==================================================================‘) print(‘error‘,item) print(‘==================================================================‘) cursor.close() conn.close()if __name__ == "__main__": for i in range(100): items = r.lrange(‘amaz:items‘,start=1000*i,end=1000*(i+1)) pool = Pool() pool.map(insert_sqlserver,items)
以上就介绍了SQL Server的相关知识,希望对SQL Server有兴趣的朋友有所帮助。了解更多内容,请关注职坐标数据库SQL Server频道!
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐




所有评论(0)