After the memcache service and php extensions are installed in the php operation on memcache cache, we can use php to operate on memcache for caching!
Summary of all PHP Memcache Client methods
The list of all memcache methods is as follows:
Memcache: add adds a value. if it already exists, false Memcache: addServer is returned. add a available server address Memcache: close to close a Memcache object Memcache:: connect. create a Memcache object memcache_debug. control and debug the function. Memcache: decrement. perform the subtraction operation on the values of a saved key. Memcache: delete a key value Memcache :: flush clear all cached data Memcache: get if a key value does not exist, falseMemcache: getExtendedStats is returned to retrieve the running system statistics of all processes in the process pool. Memcache :: getServerStatus obtains the parameter Memcache: getStats of the running server and returns some running statistics of the server. Memcache: getVersion returns the version information of the running Memcache. Memcache :: increment addition operation on the value of a saved key Memcache: pconnect create a persistent connection object for Memcache: replace-overwrite an existing key for Memcache:: set to add a value. if it already exists, overwrite Memcache: setCompressThreshold to compress Memcache: setServerParams for data larger than a certain size. modify server parameters during runtime.
Read and set cache code instances
Connect ('2017. 0.0.1 ', 11211); // obtain the value of a variable. if the value of the returned variable exists, false $ var = $ memObj-> get ('test') is returned '); // Determine whether the cache exists. if no, connect to the database to obtain the variable and save it to the memcache server if (! $ Var) {// connect to the database... if the returned value is 'test .... '; $ var = 'test .... '; $ memObj-> set ('test', $ var); // The echo output in the test cache process indicates that the cache does not exist ..... ';} echo $ var;
Delete cache
Connect ('1970. 0.0.1 ', 127); // delete the cache $ memObj-> delete ('test ');
Clear Cache
Connect ('1970. 0.0.1 ', 127); $ memObj-> flush ();
Close connection
Connect ('1970. 0.0.1 ', 127); $ memObj-> flush (); $ memObj-> close ();
After combined with php, the memcache value can be common php variables such as common variables, arrays, and objects.