314598340 发表于 2018-11-4 12:35:05

简单实现redis数据实时插入MySQL过程

import redis  import time
  import json
  import MySQLdb
  import MySQLdb
  pool=redis.ConnectionPool(host='192.168.60.21',port=6379,db=0)
  r=redis.StrictRedis(connection_pool=pool)
  #key='_'.join(["gamelog_queue",str(date),str(log),str(cmd),str(response),str(sname),str(uid)])
  while True:
  aa=r.brpop("aa",0)
  if aa == None:
  continue
  #print "list brpop:",aa
  bb=aa
  cc=aa
  #print type(bb),cc
  value=
  #print value
  try:
  dbcon = MySQLdb.connect(host='192.168.9.63', user='dlan', port=3306, passwd='root123', db='suo', charset='utf8')
  db_cursor = dbcon.cursor()
  db_insert="insert into redis_test.redis_data values(null,%s,%s)"
  db_cursor.execute(db_insert,value)
  db_cursor.execute('commit')
  except MySQLdb.Error, e:
  print "error%s", e

页: [1]
查看完整版本: 简单实现redis数据实时插入MySQL过程