"Firefly API New Document" Package Dbentrust

Source: Internet
Author: User
Tags delete key memcached

Original address: http://blog.csdn.net/uxqclm/article/details/11969653

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
    1. Type method
    2. CWD firefly/dbentrust/dbpool.py
    3. 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:
    1. "Host": "LocalHost",
    2. "User": "Root",
    3. "passwd": "111",
    4. "Port": 3306,
    5. "DB": "Test",
    6. "CharSet": "UTF8"
Replication code is used to initialize the database connection pool

Connection
Get a database connection
    1. Type method
    2. CWD firefly/dbentrust/dbpool.py
    3. Params Connecton (self)
Copy Code class Memclient
Memcached Client connection classes, which are assigned different namespaces by prefixing the class.

Connect
Connecting memcached Services
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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:
    1. "URLs": ["127.0.0.1:11211"],
    2. "hostname": "ANHEISG"
Copy code to connect to the Memcached service


Producekey (KeyName)
Regenerate key
    1. [B]type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. Params Set (KeyName, value)
Copy code successfully returns TRUE, Failure returns 0

Set_multi
Set multiple key-value pairs
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memclient.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. Params Lock (self)
Copy code changes the lock state of an object to 1

Release
Release lock
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. Params Release (self)
Copy code changes the lock state of an object to 1

Get
Gets the value corresponding to the key
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. Params update (key, values)
Copy Code Update_multi
Modifying values for multiple key-value pairs at the same time
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. Params Mdelete (self)
Copy Code INCR
Self-increment
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/memobject.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params update (key, values)
Copy Code Update_multi
Modifying values for multiple key-value pairs at the same time
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params Mdelete (self)
Copy Code iseffective
Checks whether the object is valid, returns True effectively, and returns false if invalid
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params iseffective (self)
Copy Code SYNCDB
Synchronizing data to a database
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params SyncDB (self)
Copy Code Checksync
Synchronizes data to the database and detects that the data is timed out, removing the data from memcached
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Ma = madmin ("Tb_user", ' id ', FK = ' group ', incrkey= ' id ')
    2. User2 = Ma.getobj (2)
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params Insert (self)
Copy Code load
Writes all information from the table in the database corresponding to this manager to memcached
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params Load (self)
Copy Code Madmininfo
Get information about Madmin
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params Madmininfo (self)
Copy Code Mfilter
Find compliant objects (inefficient, deprecated)
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Params Mfilter (SELF,KW)
Copy Code GETALLPKBYFK
Get a list of primary keys based on foreign keys
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. Check ()
Copy Code DELETEALLFK
Delete all foreign keys
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/mmode.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/madminanager.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/madminanager.py
    3. 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.
    1. Type method
    2. CWD firefly/dbentrust/madminanager.py
    3. 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
    1. Type method
    2. CWD firefly/dbentrust/madminanager.py
    3. Params Checkadmins (self)
Copy Code

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.