摘要:本文主要向大家介绍了SQLServer数据库之redis数据库的数据导入到SQLServer数据库中,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
本文主要向大家介绍了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频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号