The list of Memcache class functions is as follows:
Memcache::add? Adds a value that returns false if it already exists
Memcache::addserver? Add a server address that is available for use
Memcache::close? Close a Memcache object
Memcache::connect? Create a Memcache object
Memcache_debug? Control the Debug function
Memcache::d ecrement? Subtract from a value in a saved key
Memcache::d elete? Delete a key value
Memcache::flush? Clear all cached data
Memcache::get? Get a key value
Memcache::getextendedstats? Get run system statistics for all processes in the process pool
Memcache::getserverstatus? Get parameters to run the server
Memcache::getstats? Returns some running statistics for the server
Memcache::getversion? Returns the version information of the running Memcache
Memcache::increment? To add an addition to a value in a saved key
Memcache::p Connect? To create a Memcache persistent connection object
Memcache::replace-Overwrite an existing key
Memcache::set? Add a value that, if it already exists, overwrite
Memcache::setcompressthreshold? Compress data that is larger than a certain size
Memcache::setserverparams? Modifying the server's parameters at run time
Memcache::add usage
BOOL Memcache::add (String $key, mixed $var [, int $flag [, int $expire]])
Description:
If $key does not exist, use this function to store the value of $var. Functions with the same function are Memcache_add ().
Parameters:
$key: The key value that will be stored.
$var: Stored values, character types and integers are saved as original values, and other types are automatically serialized for later saving.
$flag: Whether the stored value is compressed with memcache_compressed, true means compression, and false means no compression.
$expire: The expiration time of the stored value, if 0 means it will not expire, you can use the Unix timestamp or description to indicate the time from now, but when you use the number of seconds to represent, do not exceed 2.592 million seconds (for 30 days).
return Value:
Returns TRUE if successful, and FALSE if it fails. If the $key value already exists, it returns false. In other cases, the usage of Memcache::add () is similar to Memcache::set ().
BOOL Memcache::addserver (string $host [, int $port [, bool $persistent [, int $weight [, int$timeout [, int $retry _inter Val [, BOOL $status [, Callback $failure _callback]]] []]
Description:
Add an available server address to the connection pool, the connection is opened with Memcache::addserver, the script is closed automatically after execution, or it can be closed manually with Memcache::close (). The same function is Memcache_add_server ().
When using this method (relative to Memcache::connect () and Memcache::p the Connect () method), the network connection will only be established when needed, so it will not increase the system burden by adding a lot of servers to the connection pool. Because many servers may not be used.
Failback occurs at any stage of this method execution, and as long as the other servers are normal, the failed users of these connection requests will not notice. Any type of socket or memcached server-level error can trigger a failure recovery. Normal client-side errors such as adding an existing key value do not cause a failure recovery.
Parameters:
Address of the $host server
$port Server Port
$persistent whether it is a persistent connection
$weight the weight that this server takes on all servers
Duration of $timeout Connection
$retry _interval Connection retry interval, default is 15, set to 1 means no retries
$status control the online status of the server
$failure _callback allows you to set a fallback function to handle error messages.
return Value:
Returns TRUE if successful, and FALSE if it fails.
Close the Memcache server connection. This function does not close long connections, and long connections are closed only when the Web server is shut down or restarted. The same function memcache_close ()
return Value:
Returns TRUE if successful, and FALSE if it fails.
BOOL Memcache::connect (string $host [, int $port [, int $timeout]]
Description:
Open the Memcached server connection, establish a connection to the memcached server, and the connection opened with Memcache::connect automatically shuts down after the script is executed. You can also use Memcache::close () to close the connection. The same function is Memcache_connect ().
Parameters:
$host: To the host of the link memcached is listening to, this parameter will have another special connection method Unix:///path/to/memcached.sock, that is, with the UNIX domain name sockets, in which case the port must be set to 0
$port: To the port where memcached is listening to the link, the port must be set to 0 with the UNIX domain name sockets
$timeout: The number of seconds to connect to the daemon, when you change the default value of 1 seconds, you need to consider that if your connection is too slow, you may lose the advantage of caching.
return Value:
Returns TRUE if successful, and FALSE if it fails.
Controls debug functionality, provided PHP uses the-enable-debug option when compiling, otherwise this function will not work.
Parameters:
$on _off:true to turn on debugging, false to turn off debugging
return Value:
If PHP uses the-enable-debug option when compiling, returns true, otherwise false
Memcache::d ecrement usage
int Memcache::d ecrement (String $key [, int $value])
Description:
Memcache: The function of the:d Ecremen method is to subtract from the value in a saved key, similar to memcache::increment.
You can also use the memcache_decrement () function.
Parameters:
Key: The name of the keys you want to reduce
Value: The values that you want to decrease.
return Value:
If successful, returns the value after being reduced if the failure returns false.
Example:
$memcache = new Memcache;
$memcache->connect (' localhost ', 11211);
$memcache->set (' Test_item ', 8);
$memcache->increment (' Test_item ', 4);
echo $memcache->decrement (' Test_item ', 7);
Showing 5
?>
This example even memcache::increment functions are shown in a piece.
Memcache::d elete Usage
BOOL Memcache::d elete (String $key [, int $timeout])
Description:
Delete a key value, if the parameter $timeout is set, then the stored value will expire after the set number of seconds, you can also use the function Memcache_delete ()
return Value:
Returns TRUE if successful, and FALSE if it fails.
Clears all cached data. Memcache::flush does not actually release resources, it simply marks all caches as expired, which allows the new cache to overwrite the occupied memory space. The same function is Memcache_flush ()
return Value:
Returns TRUE if successful, and FALSE if it fails.
The function of the method is to get a key value, which can be an array, and the result will contain a key-value pair.
Parameters:
$key is the value of a key or an array of keys.
$flags If this parameter exists, then $flags is related to the value written to this parameter, and these $flags are similar to the $flags in the Memcache::set () function.
return Value:
If successful, returns the value corresponding to key and returns False if it fails.
int memcache::increment (string $key [, int $value])
To add an addition to a value in a saved key
Usage reference memcache::d ecrement
Memcache::p Connect
BOOL Memcache::p Connect (string $host [, int $port [, int $timeout]])
Description:
To create a Memcache persistent connection object
Usage is similar to Memcache::connect (), where the difference is memcache::p Connect is a persistent connection established. This connection is not closed when the script finishes or the Memcache::close () function is run. The function that is the same as it is Memcache_pconnect ()
Parameters:
$host: To the host of the link memcached is listening to, this parameter will have another special connection method Unix:///path/to/memcached.sock, that is, with the UNIX domain name sockets, in which case the port must be set to 0
$port: To the port where memcached is listening to the link, the port must be set to 0 with the UNIX domain name sockets
$timeout: The number of seconds to connect to the daemon, when you change the default value of 1 seconds, you need to consider that if your connection is too slow, you may lose the advantage of caching.
BOOL Memcache::replace (String $key, mixed $var [, int $flag [, int $expire]])
Description:
Overwrite an existing key. The same function is Memcache_replace ()
Parameters:
$key: The key value that will be stored.
$var: Stored values, character types and integers are saved as original values, and other types are automatically serialized for later saving.
$flag: Whether the stored value is compressed with memcache_compressed, true means compression, and false means no compression.
$expire: The expiration time of the stored value, if 0 means it will not expire, you can use the Unix timestamp or description to indicate the time from now, but when you use the number of seconds to represent, do not exceed 2.592 million seconds (for 30 days).
return Value:
Returns TRUE if successful, and FALSE if it fails. If the $key value already exists, it returns false.
BOOL Memcache::set (String $key, mixed $var [, int $flag [, int $expire]])
Description:
Adds a value that, if it already exists, is overwrite. The same function is Memcache_set ()
Parameters:
$key: The key value that will be stored.
$var: Stored values, character types and integers are saved as original values, and other types are automatically serialized for later saving.
$flag: Whether the stored value is compressed with memcache_compressed, true means compression, and false means no compression.
$expire: The expiration time of the stored value, if 0 means it will not expire, you can use the Unix timestamp or description to indicate the time from now, but when you use the number of seconds to represent, do not exceed 2.592 million seconds (for 30 days).
return Value:
Returns TRUE if successful, and FALSE if it fails.
Compress data that is larger than a certain size. The same function is Memcache_set_compress_threshold ()
Parameters:
The Setcompressthreshold method has two parameters, the first parameter represents the critical point of processing the data size, the second parameter represents the scale of the compression, and the default is 0.2.
return Value:
Returns TRUE if successful, and FALSE if it fails.
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.