The package below is primarily a database of processing 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. There is no need to write an SQL statement here.
Class Dbpool Database Connection Pool
Initpool Initializing the database connection pool
- Type method
- CWD firefly/dbentrust/dbpool.py
- Prams Initpool (**KW)
Copy code **kw, keyword parameter, is a dictionary, key:value corresponds to config.json the corresponding value that is filled in this configuration file:
- "Host": "LocalHost",
- "User": "Root",
- "passwd": "111",
- "Port": 3306,
- "DB": "Test",
- "CharSet": "UTF8"
Replication code is used to initialize the database connection pool
Connection Get a database connection
- Type method
- CWD firefly/dbentrust/dbpool.py
- Params Connecton (self)
Copy Code class Memclient Memcached Client connection classes, which are assigned different namespaces by prefixing the class.
Connect Connecting memcached Services
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Connect (urls,hostname)
Copy code URLs, connect the IP and port number required for the memcached service Hostname, the host name that is connected The values for the above two parameters are config.json the corresponding values that are filled in this configuration file:
- "URLs": ["127.0.0.1:11211"],
- "hostname": "ANHEISG"
Copy code to connect to the Memcached service
Producekey (KeyName) Regenerate key
- [B]type method
- CWD firefly/dbentrust/memclient.py
- Params Producekey (self,keyname) [/b]
Copy code key, the key name when accessing the value, and the new key name to generate a uniform rule based on key Key must be STR type, otherwise return type error
Get Gets the value corresponding to the key
- Type method
- CWD firefly/dbentrust/memclient.py
- Prams Get (key)
Copy Code Get_multi Gets the value of more than one key at a time, faster than the For loop call get method List of @param key:list (str) keys
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Get_multi (keys)
Copy code keys is list type, keys = [Key1,key2,... keyn],key1,key2 is str type
Set Set the value of the KeyName to value
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Set (KeyName, value)
Copy code successfully returns TRUE, Failure returns 0
Set_multi Set multiple key-value pairs
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Set_multi (mapping)
Copy code mapping to DIC type, mapping = {key1:balue1,key2:value2}, successful return true, failed to return 0
incr Self-increment
- Type method
- CWD firefly/dbentrust/memclient.py
- Params incr (key, Delta)
Copy Code Key,key name Delta, increased value Adds the delta to the value of key to return the added value
Delete Delete the specified key
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Delete (key)
Copy Code Key,key name Delete key and corresponding value value, return value is 1
Delete_multi Delete multiple keys at once
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Delete_multi (keys)
Copy code keys is list type, keys = [Key1,key2,... keyn],key1,key2 is str type
Flush_all Clear all data, use with caution
- Type method
- CWD firefly/dbentrust/memclient.py
- Params Flush_all (self)
Copy Code class Memobject A mapping class that memcached data to Python objects. This class is inherited to enable customization of the memcached data format.
Producekey Regenerate key
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Producekey (Self,keyname)
Copy code key, the key name when accessing the value, and the new key name to generate a uniform rule based on key Key must be STR type, otherwise return type error
Locked Detects if the object is locked
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Lock (self)
The copy code returns the state of the object, 1 means that the object is locked and cannot be modified, and 0 indicates that it can be modified
Lock Lock Object
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Lock (self)
Copy code changes the lock state of an object to 1
Release Release lock
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Release (self)
Copy code changes the lock state of an object to 1
Get Gets the value corresponding to the key
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Get (Key)
Copy Code Get_multi Gets the value of more than one key at a time, faster than the For loop call get method
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Get_multi (keys)
Copy code keys is list type, keys = [Key1,key2,... keyn],key1,key2 is str type
Update Set the value of key to values
- Type method
- CWD firefly/dbentrust/memobject.py
- Params update (key, values)
Copy Code Update_multi Modifying values for multiple key-value pairs at the same time
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Update_multi (mapping)
Copy code mapping to type dict, mapping = {Key1:balue1,key2:value2}, return true successfully, failure returns 0 or False
Mdelete Delete all of the data contained in this class
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Mdelete (self)
Copy Code INCR Self-increment
- Type method
- CWD firefly/dbentrust/memobject.py
- Params incr (key, Delta)
Copy Code Key,key name Delta, increased value Adds the delta to the value of key to return the added value
Insert Insert all of the data contained in this class
- Type method
- CWD firefly/dbentrust/memobject.py
- Params Insert ()
Copy Code class Mmode Database to memcached direct mapping class. Can be implemented to delay asynchronous to modify data in the database, reduce the pressure on the database. And there is a custom expiration time, after the expiration of the data in the memcached will be automatically cleaned out. Here for the definition of expiration, this object is accessed in the middle of the interval. This class is implemented by inheriting Memobject
Update Set the value of key to values
- Type method
- CWD firefly/dbentrust/mmode.py
- Params update (key, values)
Copy Code Update_multi Modifying values for multiple key-value pairs at the same time
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Update_multi (mapping)
Copy code mapping to type dict, mapping = {Key1:balue1,key2:value2}, return true successfully, failure returns 0 or False
Get Gets the value corresponding to the key
- Type method
- CWD firefly/dbentrust/mmode.py
- Params get (self, key)
Copy Code Get_multi Gets the value of more than one key at a time, faster than the For loop call get method
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Get_multi (self, keys)
Copy code keys is list type, keys = [Key1,key2,... keyn],key1,key2 is str type
Delete Delete the object, just modify the state of the data to a state that has been deleted
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Delete (self)
Copy Code Mdelete Cleans up the object, synchronizes the data to the database first, and then really cleans up this data in the memcached
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Mdelete (self)
Copy Code iseffective Checks whether the object is valid, returns True effectively, and returns false if invalid
- Type method
- CWD firefly/dbentrust/mmode.py
- Params iseffective (self)
Copy Code SYNCDB Synchronizing data to a database
- Type method
- CWD firefly/dbentrust/mmode.py
- Params SyncDB (self)
Copy Code Checksync Synchronizes data to the database and detects that the data is timed out, removing the data from memcached
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Checksync (self,timeout=timeout)
Copy Code class Mfkmode FOREIGN Key Management
Class Madmin Mmode Manager, you can obtain an instance of Mmode based on the primary key. A madmin manager corresponds to a table of the database, inheriting from the Memobject class. It is instantiated in the following way
- Ma = madmin ("Tb_user", ' id ', FK = ' group ', incrkey= ' id ')
- User2 = Ma.getobj (2)
- User2.update (' name ', ' Test ')
The copy code means that the database tb_user this table, and through Ma.getobj (2), you can get the corresponding Mmode object for this record with ID 2. User2.update (' name ', ' test ') modifies the record corresponding to the Name field as ' Test '.
Insert Writes all data to the memcached.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Insert (self)
Copy Code load Writes all information from the table in the database corresponding to this manager to memcached
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Load (self)
Copy Code Madmininfo Get information about Madmin
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Madmininfo (self)
Copy Code Mfilter Find compliant objects (inefficient, deprecated)
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Mfilter (SELF,KW)
Copy Code GETALLPKBYFK Get a list of primary keys based on foreign keys
- Type method
- CWD firefly/dbentrust/mmode.py
- Params GETALLPKBYFK (SELF,FK)
Copy code FK, foreign key value Finds all eligible data in this table based on the value of the foreign key, and returns a list of the values of the primary key for the data.
Getobj Gets the Mmode object for the corresponding record based on the primary key.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Getobj (PK)
Copy code PK, the value of the primary key, return the Mmode object instance of the data corresponding to the primary key, type instance
Getobjdata Gets the field data for the corresponding record's Mmode object based on the primary key.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Getobjdata (SELF,PK)
Copy code PK, the value of the primary key, return the data corresponding to the primary key, type Dict
Getobjlist Gets the list of Mmode objects for the corresponding record based on the primary key list.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params getobjlist (self,pklist)
Copy Code pklist primary Key list, returns a list of Mmode object instances of the data corresponding to the primary key, based on the primary key in the list ([instance,instance,instance])
Deletemode Deletes the corresponding Mmode information according to the primary key.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params Deletemode (SELF,PK)
Copy code PK, value of primary key This only modifies the state of the data to a state that has been deleted.
Checkall Detects the synchronization of managed object information to the database. and process the expired objects
- Type method
- CWD firefly/dbentrust/mmode.py
- Check ()
Copy Code DELETEALLFK Delete all foreign keys
- Type method
- CWD firefly/dbentrust/mmode.py
- Params DELETEALLFK (self)
Copy code actually removes data from memcached
New Creates a new object that corresponds to the creation of a new record in the database, but is not synchronized in real time. You need to be able to actually sync to the database after the Checkall executes.
- Type method
- CWD firefly/dbentrust/mmode.py
- Params New (Self,data)
Copy Code class Madminmanager The Madmin object's manager, in effect, manages the records of the tables in the entire library, but the corresponding madmin of the table must be registered here.
Registe Register the Madmin Manager.
- Type method
- CWD firefly/dbentrust/madminanager.py
- Params Registe (self,admin)
Copy code admin, data model object instance Add an instance of the data object Madmin to the Madmin singleton manager Madminmanager
Dropadmin Canceling the management of Madmin objects
- Type method
- CWD firefly/dbentrust/madminanager.py
- Params Dropadmin (Self,adminname)
Copy Code AdminName, the name of the data model object instance Removes an instance of a data object madmin from the Madmin Singleton manager Madminmanager, based on the instance AdminName
Getadmin Gets the registered Madmin object based on the table name.
- Type method
- CWD firefly/dbentrust/madminanager.py
- Params Getadmin (Self,adminname)
Copy Code AdminName, the name of the data model object instance Get an instance of the data object Madmin from the Madmin Singleton manager Madminmanager, based on the instance AdminName
Checkadmins Synchronize Madminmanager all registered madmin corresponding records into the database and process the expired objects
- Type method
- CWD firefly/dbentrust/madminanager.py
- Params Checkadmins (self)
Copy Code |