Transferred from the co-function BBS
Split table Access KV
<?PHP/*Ecstore MongoDB class base/lib/kvstore/mongodb.php with split optimization*/classBase_kvstore_mongodb extends Base_kvstore_abstract implements Base_interface_kvstore_base {Static Private$_mongodb =NULL; function __construct ($prefix) {$prefix= Is_string ($prefix)? Preg_replace ("(\/|\\|\-|-|-|\_|_)",'.', $prefix): MD5 (Var_export ($prefix,true)); $ This->prefix =$prefix; if(!isset (SELF::$_MONGODB)) {$server= Defined ('Mongodb_server_config')? Mongodb_server_config:"mongodb://localhost:27017"; $option= Defined ('Mongodb_option_config')? Eval (mongodb_opeion_config): Array ("Connect"=TRUE); Self::$_mongodb=NewMongo ($server, $option); } $ This->mongodb = Self::$_mongodb->selectcollection ('Ecos',$ This-prefix); }//End Function Publicfunction Fetch ($key, & $value, $timeout _version=NULL) {$store= $ This->mongodb->findone (Array ('Key'=>$ This-Create_key ($key))); if(!is_null ($store) && $timeout _version < $store ['Dateline']){ if($store ['TTL'] >0&& ($store ['Dateline']+ $store ['TTL']) <Time ()) { return false; } $value= $store ['value']; return true; } return false; }//End Function Publicfunction Store ($key, $value, $ttl =0) {$store ['value'] =$value; $store ['Dateline'] =Time (); $store ['TTL'] =$ttl; $store ['Key'] = $ This-Create_key ($key); $store ['prefix'] = $ This-prefix; $res= $ This->mongodb->update (Array ('Key'= = $store ['Key']), $store, Array ("Upsert"=true)); return$res; }//End Function Publicfunction Delete ($key) {return$ This->mongodb->remove (Array ('Key'=>$ This-Create_key ($key))); }//End Function Publicfunction Recovery ($record) {$key= $record ['Key']; $store ['Key'] = $ This-Create_key ($key); $store ['value'] = $record ['value']; $store ['Dateline'] = $record ['Dateline']; $store ['TTL'] = $record ['TTL']; $res= $ This->mongodb->update (Array ('Key'= = $store ['Key']), $store, Array ("Upsert"=true)); return$res; }//End Function}//End Class
Ensure the index of each key table
Whenever the amount of MONGODB data explosion, read and write frequently, the lock table is serious, basically is the index is not added, or has not been a table-breaking scheme.
/* MONGO command-line Operations */ Use ecosshow collectionsdb.printcollectionstats () db. default. Ensureindex ({key:1}) Db.b2c.cart.ensureIndex ({key:1}) Db.tbdefine.ensureIndex ({ke:1}) Db.cache.content.nodes.ensureIndex ({key:1 }) Db.b2c.goods.ensureIndex ({key:1})
Optimize Ecstore MongoDB Big Data reading and writing efficiency