Original address:
Http://bbs.gameres.com/thread_224185.html
1, dbentrust description
This module mainly deals with the database and memcached storage. It encapsulates the mapping from memcached data to Python objects. Data stored in memcached can be manipulated in a way that manipulates Python objects, as long as memobject objects of the same name are instantiated in different processes, ensuring that the data in the object is consistent. It also contains a way to synchronize the data in this object to the database.
2. Structure Analysis
The Memobject class specifies the format of the data, all the data is stored in the memcached, in order to distinguish between different data, each data must have its own naming rules.
Mmode is the direct mapping class of database to Memcached, which represents a data in the database in memcached, which is realized by inheriting the Memobject class.
Mfkmode class represents the foreign key of the data in the memcached
The Madmin class is a Mmode manager that can obtain an instance of Mmode based on the primary key, representing a table in the database in memcached
The Madminmanager class is the manager of the Madmin object, and in effect manages the records of the tables in the entire library, but the madmin corresponding to this table must be registered here.
3. Examples of Use
1) Read the tables in the database and store them in the memcached
Line 10th, import madmin from Firefly
Line 12th, instantiate the Madmin, that is, read the information in the Tb_register table from the database, key is the second parameter, that is, Username,value is the corresponding information
Line 13th, writing data to memcached
2) Read the required data from the memcached for Operation
Line 13th, remove the data object with ID Characterid in the Madmin Manager (data from the Tb_character_matrix table stored in memcached) Mmode (Matrixmmode)
Line 14th, the data to be modified
Line 15th, change the value of key ' eye ' in the data Object (Matrixmmode) to -1
3) Use of Madmin manager Madminmanager
Line 8th, import Madminmanager from Firefly
Line 13th, add an instance of the data Object Madmin (tb_matrix_amin) to the Madmin Singleton manager Madminmanager, typically used when the server is turned on