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>