Guest User

Untitled

a guest
Jan 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import MySQLdb
  5. import memcache
  6. import MySQLdb.cursors
  7.  
  8. def dbConnect():
  9. memc = memcache.Client(['127.0.0.1:11211'], debug=1);
  10. try:
  11. conn = MySQLdb.Connect(host = "xxx.xxx.xxx.xxx",
  12. user = "login",
  13. passwd = "passwd",
  14. db = "db01",
  15. cursorclass=MySQLdb.cursors.DictCursor)
  16.  
  17. except MySQLdb.Error, e:
  18. print "Error %d: %s %" % (e.args[0], e.args[1])
  19. sys.exit(1)
  20.  
  21. try:
  22. cursor = conn.cursor()
  23. cursor.execute('select * from venues limit 5')
  24. rows = cursor.fetchall()
  25. memc.set(row['column1'],rows,60)
  26. print "updated memcached with mysql data"
  27. except:
  28. print "Error"
  29.  
  30. venue_list = memc.get('venues')
  31. for row in venue_list:
  32. print row
  33.  
  34. def main():
  35. dbConnect()
  36.  
  37.  
  38. if __name__ == "__main__":
  39. main()
Add Comment
Please, Sign In to add comment