Memcache functions in PHP
Memcache functions are listed as follows:
Memcache: add? Add a value. if it already exists, false is returned.
Memcache: addServer? Add an available server address
Memcache: close? Disables 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? Obtain the parameters of the running server
Memcache: getStats? Returns the running statistics of the server.
Memcache: getVersion? Returns the version information of the running Memcache instance.
Memcache: increment? Adds the value of a saved key.
Memcache: pconnect? Creates a persistent connection object for Memcache.
Memcache: replace-overwrite an existing key
Memcache: set? Add a value. if it already exists, overwrite it.
Memcache: setCompressThreshold? Compress data larger than a certain size
Memcache: setServerParams? Modify server parameters at runtime
Memcache: add usage
Bool Memcache: add (string $ key, mixed $ var [, int $ flag [, int $ expire])
Note:
If $ key does not exist, use this function to store the value of $ var. The function with the same functions is memcache_add ().
Parameters:
$ Key: the key value to be stored.
$ Var: the stored values, values, and integer types are saved based on the original values. Other types are automatically serialized and saved.
$ Flag: whether to use MEMCACHE_COMPRESSED to compress the stored value. true indicates compression, and false indicates no compression.
$ Expire: the expiration time of the stored value. if it is 0, it indicates that it will not expire. you can use a unix timestamp or description to indicate the time from now on, however, when you use the number of seconds, do not exceed 2592000 seconds (30 days ).
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned. If the $ key value already exists, FALSE is returned. In other cases, the usage of Memcache: add () is similar to that of Memcache: set ().
Bool Memcache: addServer (string $ host [, int $ port [, bool $ persistent [, int $ weight [, int $ timeout [, int $ retry_interval [, bool $ status [, callback $ failure_callback])
Note:
Add an available server address to the connection pool, and enable the connection with Memcache: addServer. the connection is automatically closed after the script is executed, or you can use Memcache: close () to manually close the connection pool. The same function is memcache_add_server ().
When this method is used (compared with the Memcache: connect () and Memcache: pconnect () methods), the network connection is established only when necessary, therefore, the system load will not be increased because many servers are added to the connection pool, because many servers may not be used.
Fault recovery will occur at any stage of the method execution. as long as other servers are normal, the failed users of these connection requests will not notice it. Any socket or memcached server-level error can trigger fault recovery. Normal client errors, such as adding an existing key value, will not cause fault recovery.
Parameters:
$ Host server address
$ Port server port
$ Persistent is a persistent connection
$ Weight of this server among all servers
$ Timeout connection duration
$ Retry_interval specifies the retry interval of the connection. the default value is 15. if the value is-1, no retry is performed.
$ Status controls the online status of the server
$ Failure_callback allows you to set a callback function to handle error messages.
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Disable the memcache server connection. This function does not close persistent connections. persistent connections are closed only when the web server is closed or restarted. Same function memcache_close ()
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Bool Memcache: connect (string $ host [, int $ port [, int $ timeout])
Note:
Open the memcached server connection and establish a connection to the memcached server. the connection opened with Memcache: connect will be automatically closed after the script is executed. You can also use Memcache: close () to close the connection. The same function is memcache_connect ().
Parameters:
$ Host: the host that points to the link memcached is listening to. this parameter has another special connection method unix: // path/to/memcached. sock, that is, the unix domain name sockets. in this case, the port must be set to 0.
$ Port: The port pointing to the link memcached is listening to. when the unix domain name sockets is used, the port must be set to 0.
$ Timeout: the number of seconds used to connect to the Daemon. when you change the default value of 1 second, consider it. if your connection is too slow, you may lose the cache advantage.
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Control the debugging function, provided that the-enable-debug option is used during php compilation, otherwise this function will not work.
Parameters:
$ On_off: true indicates that debugging is enabled, and false indicates that debugging is disabled.
Return value:
If the-enable-debug option is used during php compilation, true is returned; otherwise, false is returned.
Memcache: decrement usage
Int Memcache: decrement (string $ key [, int $ value])
Note:
The Memcache: decremen method is used to subtract values from a saved key. its usage is similar to that of Memcache: increment.
You can also use the memcache_decrement () function.
Parameters:
Key: name of the Key to be removed
Value: The Value to be reduced.
Return value:
If the operation succeeds, the value after reduction is returned. if the operation fails, false is returned.
Example:
$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 11211 );
$ Memcache-> set ('test _ item', 8 );
$ Memcache-> increment ('test _ item', 4 );
Echo $ memcache-> decrement ('test _ item', 7 );
// Display 5
?>
In this example, the Memcache: increment function is used together.
Memcache: delete usage
Bool Memcache: delete (string $ key [, int $ timeout])
Note:
Delete a key value. if the $ timeout parameter is set, the stored value will expire after the set number of seconds. you can also use the memcache_delete () function ()
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Clear all cached data. Memcache: flush does not actually release resources. it only marks all the caches as expired, so that the new cache can overwrite the occupied memory space. The same function is memcache_flush ()
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
The function of the method is to obtain a key value. The key value can be an array and the result contains a key-value pair.
Parameters:
$ Key is the key value or the array value of a key.
$ Flags if this parameter exists, $ flags is related to the value written to this parameter. these $ flags are similar to $ flags in the Memcache: set () function.
Return value:
If the operation succeeds, the value corresponding to the key is returned. if the operation fails, false is returned.
Int Memcache: increment (string $ key [, int $ value])
Adds the value of a saved key.
For usage instructions, refer to Memcache: decrement.
Memcache: pconnect
Bool Memcache: pconnect (string $ host [, int $ port [, int $ timeout])
Note:
Creates a persistent connection object for Memcache.
Usage is similar to Memcache: connect (). The difference is that Memcache: pconnect is a persistent connection established. This connection will not be closed either after the script is executed or when the Memcache: close () function is run. The same function as memcache_pconnect ()
Parameters:
$ Host: the host that points to the link memcached is listening to. this parameter has another special connection method unix: // path/to/memcached. sock, that is, the unix domain name sockets. in this case, the port must be set to 0.
$ Port: The port pointing to the link memcached is listening to. when the unix domain name sockets is used, the port must be set to 0.
$ Timeout: the number of seconds used to connect to the Daemon. when you change the default value of 1 second, consider it. if your connection is too slow, you may lose the cache advantage.
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Bool Memcache: replace (string $ key, mixed $ var [, int $ flag [, int $ expire])
Note:
Overwrites an existing key. The same function is memcache_replace ()
Parameters:
$ Key: the key value to be stored.
$ Var: the stored values, values, and integer types are saved based on the original values. Other types are automatically serialized and saved.
$ Flag: whether to use MEMCACHE_COMPRESSED to compress the stored value. true indicates compression, and false indicates no compression.
$ Expire: the expiration time of the stored value. if it is 0, it indicates that it will not expire. you can use a unix timestamp or description to indicate the time from now on, however, when you use the number of seconds, do not exceed 2592000 seconds (30 days ).
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned. If the $ key value already exists, FALSE is returned.
Bool Memcache: set (string $ key, mixed $ var [, int $ flag [, int $ expire])
Note:
Add a value. if it already exists, overwrite it. The same function is memcache_set ()
Parameters:
$ Key: the key value to be stored.
$ Var: the stored values, values, and integer types are saved based on the original values. Other types are automatically serialized and saved.
$ Flag: whether to use MEMCACHE_COMPRESSED to compress the stored value. true indicates compression, and false indicates no compression.
$ Expire: the expiration time of the stored value. if it is 0, it indicates that it will not expire. you can use a unix timestamp or description to indicate the time from now on, however, when you use the number of seconds, do not exceed 2592000 seconds (30 days ).
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
Compress data larger than a certain size. The same function is memcache_set_compress_threshold ()
Parameters:
The setCompressThreshold method has two parameters. The first parameter indicates the critical point for processing data size, and the second parameter indicates the compression ratio. the default value is 0.2.
Return value:
If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
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.