Firefly Official Tutorials: Dbentrust Instructions - 9miao/Firefly GitHub Wiki

Firefly Official Tutorials: Dbentrust Instructions

1. Dbentrust Introduction

Debentrust is mainly dealing with database and memcached storage, and encapsulates inside mapping memcached data to python objects. It could operate stored data in memcached by manipulating python object, and make sure the data consistency of objects, as long as instantiating homonymous memobject objects in disparate process. It can also synchronize object’s data to database.

2. Structural Analysis


MemObject class stipulates the format of data, and all data are stored in memcached. In order to distinguish different data, each one should have its own naming rules.
Mmode, representing a piece of data in database, is a straightforward mapping class from database to memcached which implements itself via inheritance of MemObject.
MFKMode class represents corresponding foreign key of data in memcached.
MAdmin class is mmode supervisor, and is able to obtain a mmode instance according to the primary key, and represents a database table in memcached.
MadminManager class is Madmin object supervisor, actually is the management of whole database table records, yet the corresponding table Madmin must be registered here.

3. Example

1) Read table in database and store in memcached

Line 10: import Madmin from Firefly
Line 12: instantiating Madmin, which is reading tb_register’s table information from database, here key is second parameter (username) and value is corresponding information.
Line 13: write data to memcached

2) Read required data from memcached to operate

Line 13: Get data object Mmode (matrixMmode) (id: characterid) from MadminManager (data of tb_character_matrix stored in memcached)
Line 14: data that is required to modify
Line 15: modify key’s value from ‘eye’ to ‘-1’ in data object (matrixMmode)

3) MadminManager Usage

Line 8: import MadminManager from Firefly
Line 13: add data object Madmin’s instance (tb_matrix_amin) to Madmin singleton MadminManger, it’s usually used in server starting.
Line 14: synchronizing all registered madmin’s corresponding records in MadminManger to database as well as handling expired objects, it’s usually used in server closing. (Note: only synchronizing data object Madmin’s instance data that have been registered in MadminManager).

⚠️ **GitHub.com Fallback** ⚠️