标签:style asc inf 要求 code app admin %s set
import redis,json,pymysql mysql_info ={ ‘host‘:"118.244.34.43", "user":‘jjgz‘, "password":‘123456‘, ‘port‘:3306, "db":‘jjgz‘ } redis_info={ ‘host‘:‘118.224.32.20‘, ‘password‘:‘HKdsss139bc&*‘, ‘db‘:10, ‘port‘:6379, ‘decode_responses‘:True } def con_mysql(table_name=‘app_myuser‘): conn = pymysql.connect(**mysql_info) cur = conn.cursor(pymysql.cursors.DictCursor) sql =‘select * from %s limit 10;‘%table_name cur.execute(sql) data = cur.fetchall() cur.close() conn.close() return data def set_redis(): r = redis.Redis(**redis_info) data = con_mysql() #处理表数据,写入到redis,要求格式{tanailing:key,{‘id‘: 1122, ‘username‘: ‘liuyana03‘, ‘passwd‘: ‘123658‘, ‘is_admin‘: 1}} for d in data: key =‘TAL:%s‘%d.get(‘username‘) d=json.dumps(d,ensure_ascii=False) r.set(key,d) if __name__ == ‘__main__‘: set_redis()
标签:style asc inf 要求 code app admin %s set
原文地址:https://www.cnblogs.com/miyatest/p/10351744.html