Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import MySQLdb
- import memcache
- import MySQLdb.cursors
- def dbConnect():
- memc = memcache.Client(['127.0.0.1:11211'], debug=1);
- try:
- conn = MySQLdb.Connect(host = "xxx.xxx.xxx.xxx",
- user = "login",
- passwd = "passwd",
- db = "db01",
- cursorclass=MySQLdb.cursors.DictCursor)
- except MySQLdb.Error, e:
- print "Error %d: %s %" % (e.args[0], e.args[1])
- sys.exit(1)
- try:
- cursor = conn.cursor()
- cursor.execute('select * from venues limit 5')
- rows = cursor.fetchall()
- memc.set(row['column1'],rows,60)
- print "updated memcached with mysql data"
- except:
- print "Error"
- venue_list = memc.get('venues')
- for row in venue_list:
- print row
- def main():
- dbConnect()
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment