redis
Posted miyatest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis相关的知识,希望对你有一定的参考价值。
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()
以上是关于redis的主要内容,如果未能解决你的问题,请参考以下文章