Memcache all methods and parameters

Source: Internet
Author: User
Tags memcached server port

memcache a list of all the methods of the function is as follows:

Reference http://www.php.net/manual/zh/function.Memcache-add.php

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-Closes a Memcache object

Memcache::connect-Create a Memcache object

Memcache_debug-Control Debug function

Memcache::d ecrement-Subtract from the value in a saved key

Memcache::d elete-delete a key value

Memcache::flush-Clears all cached data

Memcache::get-Gets a key value

Memcache::getextendedstats-Gets the running system statistics for all processes in the process pool

Memcache::getserverstatus-Get parameters to run the server

Memcache::getstats-Returns some run statistics for the server

Memcache::getversion-Returns the version information of the running Memcache

Memcache::increment-Adds an addition to the value in a saved key

Memcache::p Connect-Create a Memcache persistent connection object

Memcache::replace-Overwrite an existing key

Memcache::set-Adds a value that, if already present, overwrite

Memcache::setcompressthreshold-compression of data 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 ().

Example:

<?php

$memcache _obj = Memcache_connect ("localhost", 11211);


Memcache_add ($memcache _obj, ' var_key ', ' Test variable ', false, 30);


$memcache _obj->add (' Var_key ', ' Test variable ', false, 30);

?>

Memcache::addserver usage

BOOL memcache::addserver (String $host [, int $port [, BOOL $persistent [, int $w Eight [, int $timeout [, int $retry _interval [, BOOL $status [, Callback $failure _call back]] []]

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.

Example:

<?php

$memcache = new Memcache;
$memcache->addserver (' Memcache_host ', 11211);
$memcache->addserver (' Memcache_host2 ', 11211);

$memcache _obj = memcache_connect (' memcache_host ', 11211);
Memcache_add_server ($memcache _obj, ' Memcache_host2 ', 11211);

?>

Memcache::close usage

BOOL memcache::close (void)

Description

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.

Example:

<?php


$memcache _obj = memcache_connect (' memcache_host ', 11211);

Memcache_close ($memcache _obj);


$memcache _obj = new Memcache;
$memcache _obj->connect (' Memcache_host ', 11211);

$memcache _obj->close ();

?>

Memcache::connect usage

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.

Example:

<?php

$memcache _obj = memcache_connect (' memcache_host ', 11211);

$memcache = new Memcache;
$memcache->connect (' Memcache_host ', 11211);

?>

Memcache::d ebug

BOOL memcache_debug (bool $on _off )

Description

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:

<?php

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

Example:

<?php


$memcache _obj = memcache_connect (' memcache_host ', 11211);


Memcache_delete ($memcache _obj, ' Key_to_delete ', 10);


$memcache _obj = new Memcache;
$memcache _obj->connect (' Memcache_host ', 11211);

$memcache _obj->delete (' Key_to_delete ', 10);

?>

Memcache::flush

BOOL Memcache::flush (void)

Description

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.

Example:

<?php


$memcache _obj = memcache_connect (' memcache_host ', 11211);

Memcache_flush ($memcache _obj);

$memcache _obj = new Memcache;
$memcache _obj->connect (' Memcache_host ', 11211);

$memcache _obj->flush ();

?>

Memcache::get

String memcache::get (String $key [, int & $flags ])

Array memcache::get (array $keys [, array & $flags ])

Description

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.

Example:

<?php


$memcache _obj = memcache_connect (' memcache_host ', 11211);
$var = Memcache_get ($memcache _obj, ' Some_key ');


$memcache _obj = new Memcache;
$memcache _obj->connect (' Memcache_host ', 11211);
$var = $memcache _obj->get (' Some_key ');


$memcache _obj = memcache_connect (' memcache_host ', 11211);
$var = Memcache_get ($memcache _obj, Array (' Some_key ', ' Another_key '));


$memcache _obj = new Memcache;
$memcache _obj->connect (' Memcache_host ', 11211);
$var = $memcache _obj->get (Array (' Some_key ', ' Second_key '));

?>

Memcache::getextendedstats

Array memcache::getextendedstats ([string $type [, int $slabid [, int $limit ]])

Description

Gets the running system statistics for all processes in the process pool. The same function is memcache_get_extended_stats ()

Parameters:

$type indicates the type of return required: RESET, malloc, maps, Cachedump, slabs, items, sizes;

$slabid used when the first parameter is set to "Cachedump".

$limit used when the first parameter is set to "Cachedump".

return value:

If successful, the statistics are returned, and the failure returns false

Example:

<?php
$memcache _obj = new Memcache;
$memcache _obj->addserver (' Memcache_host ', 11211);
$memcache _obj->addserver (' Failed_host ', 11211);

$stats = $memcache _obj->getextendedstats ();

Slabs mechanism allocation of memory management

$statsslab = $memcache _obj->getextendedstats (slabs);

?>

Memcache::getserverstatus

int memcache::getserverstatus (String $host [, int $port ])

Description

Gets the parameters that run the server. Returns the status of a server online or offline. The same function is Memcache_get_server_status ()

Parameters:

$host: The host of the connection you are listening to

$port the port of the host to which the connection is being tuned, the default is 11211

return value:

Successful return to the server state, the server does not start will return 0, the other number when the server is a startup state.

Example:

<?php


$memcache = new Memcache;
$memcache->addserver (' Memcache_host ', 11211);
echo $memcache->getserverstatus (' Memcache_host ', 11211);


$memcache = Memcache_connect (' memcache_host ', 11211);
Echo memcache_get_server_status ($memcache, ' memcache_host ', 11211);

?>

Memcache::getstats

Array memcache::getstats ([string $type [, int $slabid [, int $limit ]])

Description

Returns some run statistics for the server. The same function is Memcache_get_stats ()

Parameters:

$type indicates the type of return required: RESET, malloc, maps, Cachedump, slabs, items, sizes;

$slabid used when the first parameter is set to "Cachedump".

$limit used when the first parameter is set to "Cachedump".

return value:

The statistics array for the server was successfully returned, and the failure returned false.

Memcache all methods and parameters

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.