import pymysql,redis,json
r=redis.Redis(host='118.xx.xx.xxx',password='xxxc&*',db=1)

coon=pymysql.connect(
host='118.xx.xx.xx',user='xxx',passwd='123456',
port=3306,db='xxx',charset='utf8'
)


cur=coon.cursor(cursor=pymysql.cursors.DictCursor)
cur.execute('select * from my_user; ')

all_data=cur.fetchall()

for data in all_data:
k=data.get('username')
r.hset('stu_info_jd',k,json.dumps(data))
cur.close()
coon.close()
posted on 2018-05-11 23:16  彼得潘jd  阅读(97)  评论(0编辑  收藏  举报