And communicate with the daemon through the memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries). When a server s stops running or crashes, all key/value pairs stored on s will be lost. Developed by danga interactive, memcached improves the access speed of livejournal.com. The number of dynamic page views per second on the lj is several thousand, and the number of users is 7 million. Memcached greatly reduces the database load and makes it easier to allocate resources for faster access.
Common memcache methods
Memcache: add-add a value. If it already exists, false is returned.
Memcache: addserver-add an available server address
Memcache: close-close a memcache object
Memcache: connect-create a memcache object
Memcache: debug-control debugging
Memcache: decrement-deletes the value of a saved key.
Memcache: delete-delete a key value
Memcache: flush-clear all cached data
Memcache: get-get a key value
Memcache: getextendedstats-obtains the running system statistics of all processes in the process pool.
Memcache: getserverstatus-get the parameters of the running server
Memcache: getstats-return some running statistics of the server
Memcache: getversion-returns the version information of the running memcache.
Memcache: increment-adds the value of a saved key.
Memcache: pconnect-creates a persistent connection object for memcache.
Memcache: replace-r: overwrites an existing key.
Memcache: set-add a value. If it already exists, overwrite it.
Memcache: setcompressthreshold-compresses data larger than a certain size
Memcache: setserverparams-modify server parameters at runtime
Memcache method usage
The code is as follows:
| The code is as follows: |
Copy code |
<? Php Tutorial
$ Memcache = new memcache;
$ Memcache-> connect ('127. 0.0.1 ', 127) or die ("connection failed ");
$ Memcache-> set ('name', 'Zhang San ');
$ Val = $ memcache-> get ('name ');
?> |
Note: The complete version of the set method, set (key name, key value, whether to compress, retention time)
The code is as follows:
| The code is as follows: |
Copy code |
<? Php
$ Memcache = new memcache;
$ Memcache-> connect ('127. 0.0.1 ', 127) or die ("connection failed ");
$ Memcache-> set ('name', array ('one', 'two '));
$ Val = $ memcache-> get ('name ');
Print_r ($ val );
$ Memcache-> close ();
?> |