PHP Cache Technology: Part 3 of memcache Functions

Source: Internet
Author: User

 

Transferred from www.5iphp.com

Memcache: getversion

StringMemcache: getversion(Void)

 

Note:

Returns the version information of the running memcache instance. Same Function memcache_get_version ()

 

Return Value:

The version of the server is returned. if the version fails, false is returned.

 

Example:

<? PHP

/* Object-oriented API */
$ Memcache = new memcache;
$ Memcache-> connect ('memcache _ host', 11211 );
Echo $ memcache-> getversion ();

/* Process-oriented API */
$ Memcache = memcache_connect ('memcache _ host', 11211 );
Echo memcache_get_version ($ memcache );

?>

 

 

Memcache: Increment

IntMemcache: Increment(String$ Key[, Int
$ Value])

Adds the value of a saved key.

For usage instructions, refer to memcache: decrement.

 

 

Memcache: pconnect

BoolMemcache: 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. The connection is completed in the script or the memcache: Close () function is not executed.. 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.

<? PHP

/* Process-oriented API */
$ Memcache_obj = memcache_pconnect ('memcache _ host', 11211 );

/* Object-oriented API */

$ Memcache_obj = new memcache;
$ Memcache_obj-> pconnect ('memcache _ host', 11211 );

?>

 

 

Memcache: replace

BoolMemcache: 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: used or notMemcache_compressedTo compress the stored values,TrueIndicates compression,FalseIndicates 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.

 

<? PHP

$ Memcache_obj = memcache_connect ('memcache _ host', 11211 );

/* Process-oriented API */
Memcache_replace ($ memcache_obj, "test_key", "some variable", false, 30 );

/* Object-oriented API */
$ Memcache_obj-> Replace ("test_key", "some variable", false, 30 );

?>

 

 

Memcache: Set

BoolMemcache: 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: used or notMemcache_compressedTo compress the stored values,TrueIndicates compression,FalseIndicates 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.

 

Example:

 

/* Object-oriented API */

$memcache_obj = new Memcache;

/* ConnectmemcachedServer */
$memcache_obj->connect('memcache_host', 11211);

/*
Give key'var_key'Set Value, Compression is used, and the latency is50Seconds
*/
$memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);

echo $memcache_obj->get('var_key');

 

Memcache: setcompressthreshold

 

BoolMemcache: setcompressthreshold(Int$ Threshold[, Float
$ Min_savings])

Note:

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.

 

Example:

<? PHP

/* Object-oriented API */

$ Memcache_obj = new memcache;
$ Memcache_obj-> addserver (『 memcache _ host', 11211 );
$ Memcache_obj-> setcompressthreshold (20000, 0.2 );

/* Process-oriented API */

$ Memcache_obj = memcache_connect ('memcache _ host', 11211 );
Memcache_set_compress_threshold ($ memcache_obj, 20000, 0.2 );

?>

 

 

Memcache: setserverparams

BoolMemcache: setserverparams(String$ Host[, Int
$ Port[, Int$ Timeout[, Int$ Retry_interval[, Bool
$ Status
[, Callback$ Failure_callback])

Note:

Modify server parameters at runtime. The same function is memcache_set_server_params ().

 

Parameters:

$ Host server address

$ Port server port

$ 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.

 

Example:

<? PHP

Function _ callback_memcache_failure ($ host, $ port ){
Print "memcache '$ HOST: $ port' failed ";
}

/* Object-oriented API */

$ Memcache = new memcache;

// Add a server in offline mode
$ Memcache-> addserver ('memcache _ host', 11211, false, 1, 1,-1, false );

// Set the server to online
$ Memcache-> setserverparams ('memcache _ host', 11211, 1, 15, true, '_ callback_memcache_failure ');

/* Process-oriented API */

$ Memcache_obj = memcache_connect ('memcache _ host', 11211 );
Memcache_set_server_params ($ memcache_obj, 'memcache _ host', 11211, 1, 15, true, '_ callback_memcache_failure ');

?>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.