Firefly--dbentrust Sample Demo (source + tutorial)

Source: Internet
Author: User
Tags memcached

Original address: http://www.9miao.com/question-15-54002.html

Firefly--dbentrust Sample Description
First, database preparation
This example shows the data processing between Firefly and MySQL and memcached, so prepare the database first. (Database tools are using Sqlyogent)
1. Create a database

<ignore_js_op>



2. Build a table
The following is a simple role table (player)

<ignore_js_op>



Ii. interaction between Firefly and MySQL (test_dbpool.py)

<ignore_js_op>



The SQL statement in line 18th can be any legitimate SQL statement that operates on the database. This example runs the file by querying the rank of the role with ID 100001 in the player table:

<ignore_js_op>



The printed result is 40, exactly the same as in the database. (The final result is the cause of the tuple, see Python mysqldb This module usage, online tutorials a lot, here no longer explain.) )

Iii. interaction between Firefly and Memcached (test_mclient.py)

<ignore_js_op>



Before running this example, it is important to ensure that the memcached service is working properly before sending a document about Memcached installation and configuration, which is no longer explained here. Run the following file:

<ignore_js_op>



Iv. Comprehensive Example (test.py)

<ignore_js_op>



<ignore_js_op>



43,44 line is to synchronize data from the Player table in the database to memcached
The 46 line is to register the data of the player table in the Madminmanager, Madminmanager mentioned before, essentially equivalent to the database "library", manage all the "table"

55 The line synchronizes all table data registered in the Madminmanager to the database, typically for daily game data backups (avoiding data loss due to a special incident causing the server to shut down, but it consumes performance, suggests a bit longer interval), and backs up data before the server shuts down.
To run the file:

<ignore_js_op>



It can be seen that the data in memcached levels has been changed from 40 to 20, the following see whether the database changes:

<ignore_js_op>

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.