[Summary] During the interview, PHP [memcache protocol] was asked about many aspects of memcache. I found that I only know set and get is not enough, therefore, refresh the basic content Memcache-Memcache class Memcache: add-add an entry to the cache server [summary] PHP [memcache protocol]
During the interview, I was asked many questions about memcache. I found that I only know set and get is not enough.
Basic content
- Memcache-Memcache class
- Memcache: add-add an entry to the cache server
- Memcache: addServer-add a memcache server to the connection pool
- Memcache: close-close memcache connection
- Memcache: connect-open a memcached server connection
- Memcache: decrement-reduce the element value
- Memcache: delete-delete an element from the server
- Memcache: flush-clean (delete) all elements that have been stored
- Memcache: get-an element retrieved from the server
- Memcache: getExtendedStats-statistics on all servers in the cache server pool
- Memcache: getServerStatus-used to obtain the online/offline status of a server
- Memcache: getStats-get server statistics
- Memcache: getVersion-the server version is returned.
- Memcache: increment-add the value of an element
- Memcache: pconnect-open a persistent connection to the server
- Memcache: replace-replace the value of an existing element
- Memcache: set-Store data at the server
- Memcache: setCompressThreshold-enable automatic compaction
- Memcache: setServerParams-modify server parameters and status during runtime
Situations that are frequently encountered in actual scenarios
-------------------------------
Memcache: add ()
If no value exists, assign another value.
Memcache: addServer ()
When using this method, the network connection will not be established immediately, but will not be established until it is actually used. Therefore, when a large number of servers are added to the connection pool, there is no overhead because they may not be used.
Memcache: decrement ()
When the element does not existNoCreate it
First, convert the current value of the element to a value and then subtract it.Value
The value of the new element is not smaller than 0.
Memcache: flush ()
Immediately invalidate all existing elements
It does not actually release any resources, but only marks that all elements are invalid, so the memory that has been used will be rewritten by new elements.
Memcache: increment ()
NoCreate an element when the corresponding key element does not exist.
Adds the value of the specified element.Value.
If the specifiedKeyThe corresponding element is not of the numerical type and cannot be converted to a numerical value.Value.
Memcache: replace ()
PassKeyTo find the element and replace its value.
If the element corresponding to the key does not existFALSE.
---------------------------------------------