Firefly Getting Started tutorial Firefly, MySQL, and memcached common use

Source: Internet
Author: User
Tags memcached

  1. #coding: UTF8
  2. ########## #firefly, MySQL and memcached common use ###########
  3. From Firefly.dbentrust.dbpool import Dbpool
  4. From firefly.dbentrust.memclient import mclient
  5. From Firefly.dbentrust.mmode import madmin
  6. hostname = "localhost" #要连接的数据库主机名
  7. user = "root" #要连接的数据库用户名
  8. Password = "111" #要连接的数据库密码
  9. Port = 3306 # 3306 is the TCP port number used by the MySQL service and is typically 3306 by default
  10. dbname = "Test1" #要使用的数据库库名
  11. CharSet = "UTF8" #要使用的数据库的编码
  12. Dbpool.initpool (host = hostname,
  13. user = user,
  14. passwd = password,
  15. Port = port,
  16. db = dbname,
  17. char = CharSet
  18. # #firefly重新封装的连接数据库的方法, this step is to initialize the database connection pool so that you can connect to the database you want to use
  19. address = ["127.0.0.1:11211"] #要连接的Memcached的主机地址端口号
  20. hostname = "localhost" #要连接的Memcached的主机名
  21. Mclient.connect (address, hostname) #firefly重新封装的连接Memcached的方法 so you can connect to the memcached you want to use
  22. Player = Madmin ("Player", "id") #实例化一个MAdmin管理器 to manage the data in the player table, which is the name of the table you want to manage, the ID is the primary key of the table
  23. #不清楚MAdmin是什么的童鞋请移步http: There's a dbentrust in//firefly.9miao.com/wiki/index.htm,wiki. Use the document, which details Firefly the association between several classes and databases
  24. Player.insert () #将管理器player注册到memcached中
  25. m = Player.getobj (100001) #取出player表中主键 (this example is ID) is 100001 of this data object (Mmode)
  26. data = M.get ("Data") #获取数据对象m里面包含的信息
  27. Print data# printing information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.