Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the php memcached methods?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What are the php memcached methods? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Php memcached methods include: 1, set (); 1, add (); 3, replace (); 4, get (); 5, delete (); 6, increment (); 7, decrement (); 8, flush (); 9, connect () and so on.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Summary of methods for PHP to operate Memcached

(1) memcache extension

1. Bool Memcache::set (string $key, mixed $var [, int $flag [, int $expire]])

If # Key exists, the value will be updated, and if it does not exist, the KMTV pair will be set. Note: $var can store any data

2. Bool Memcache::add (string $key, mixed $var [, int $flag [, int $expire]])

# add key only when it does not exist

3. Bool Memcache::replace (string $key, mixed $var [, int $flag [, int $expire]])

# replace the existing key value. If there is no key, an error is returned.

4. String Memcache::get (string $key [, int & $flags])

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

# get one or more values

5. Bool Memcache::delete (string $key [, int $timeout = 0])

# delete the key element. If timeout is set, delete it after a few seconds

# [Note] some versions corresponding to memcached using timeout will cause deletion failure (0 OK)

6. Int Memcache::increment (string $key [, int $value = 1])

If # key exists and can be converted into numbers, add int; or replace it with value directly. When key does not exist, false is returned

7. Int Memcache::decrement (string $key [, int $value = 1])

8. Bool Memcache::flush (void)

# all elements are invalid

9. Bool Memcache::connect (string $host [, int $port [, int $timeout=1]])

# Connect to the memcache server and shut it down automatically after executing the script (active shutdown using close)

10. Bool Memcache::close (void)

# close the link to memcache (this function does not close persistent connections)

11. Mixed Memcache::pconnect (string $host [, int $port [, int $timeout]])

# establish a persistent connection

Bool Memcache::addServer (string $host [, int $port = 11211 [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback [, int $timeoutms])

# add a server to the connection pool. Services opened by this method will shut down or actively shut down close at the end of the script

# with this method, network connections do not necessarily connect immediately, but only when this server is needed, so there is no overhead even if a large number of servers are added to the connection pool

Parameters:

Whether $persistent is persisted. Default is true.

$weight represents weight

Retry time when the connection to the retry_interval server fails. Default is 15 seconds.-1 means no retry.

$status controls whether the server is marked online (if the connection fails and the connection pool lacks one server, the original allocation algorithm will be affected)

The function executed after the failure_callback connection fails (before the failover), including two parameters, the failed host host and port

13. Array Memcache::getExtendedStats ([string $type [, int $slabid [, int $limit = 100])

# getExtendedStats () returns server statistics of a two-dimensional associated data

# getExtendedStats ('slabs') gets the id of active slabs chunks on each server

# getExtendedStats ('cachedump', $slabid, $limit) gets the cached items in each slab

Parameters:

# types of statistics expected to be crawled by type. Available values are {reset, malloc, maps, cachedump, slabs, items, sizes}

# slabid is used in conjunction with the parameter type to copy data in chunks from the specified slab. The cachedump command will completely occupy the server and is usually used for strict debugging.

# limit is used in conjunction with the parameter type to set the number of entities obtained from the server when cachedump.

14. Int Memcache::getServerStatus (string $host [, int $port = 11211])

# returns the status of a server. 0 means the server is offline, and non-0 means online.

15. Array Memcache::getStats ([string $type [, int $slabid [, int $limit = 100])

# getStats () returns server statistics for an associated data. Same as above

16. String Memcache::getVersion (void)

# return the version number

17. Bool Memcache::setCompressThreshold (int $threshold [, float $min_savings])

# enable automatic compression of large values

Parameters:

# threshold controls the threshold for automatic compression.

# min_saving specifies the compression ratio of the actual stored values that are compressed, and the supported values must be between 0 and 1. The default value is 0.2, which means 20% compression.

Bool Memcache::setServerParams (string $host [, int $port = 11211 [, int $timeout [, int $retry_interval = false [, bool $status [, callback $failure_callback])

# used to modify server parameters at run time

# parameters same as above

(2) memcached extension

1. Memcached::__construct ([string $persistent_id])

# by default, Memcached instances are terminated after the request is completed. However, you can specify a unique ID for each instance through persistent_id at creation time, and share the instance between requests. All instances created with the same persistent_ id value share the same connection.

2. Public bool Memcached::addServer (string $host, int $port [, int $weight = 0])

# add the specified server to the server pool, and no connection with the server will be established at this time

3. Public bool Memcached::addServers (array $servers)

# add multiple servers to the service pool

4. Public bool Memcached::cas (float $cas_token, string $key, mixed $value [, int $expiration])

# performs a "check and set" operation, which can write the value only if the value corresponding to the key has not been modified by other clients after the last value is taken by the current client. Check through the cas_token parameter

5. Public bool Memcached::casByKey (float $cas_token, string $server_key, string $key, mixed $value [, int $expiration])

# specify the server, as above

# [$server_key is also an ordinary key. * the working process of the ByKey series interface is as follows: first, hash $server_key to get the server where $server_key should be stored, and then perform the corresponding operation on the server where $server_key is located]

6. Public bool Memcached::set (string $key, mixed $value [, int $expiration])

# Save the value value (which can be any valid non-resource php type) to key

7. Public bool Memcached::setByKey (string $server_key, string $key, mixed $value [, int $expiration])

# specify the server, as above

8. Public bool Memcached::setMulti (array $items [, int $expiration])

# storing multiple elements

# $items array ('key'= >' value')

9. Public bool Memcached::setMultiByKey (string $server_key, array $items [, int $expiration])

# specify the server, as above

10. Public bool Memcached::add (string $key, mixed $value [, int $expiration])

# add an element to a new key, but the existence of key fails

11. Public bool Memcached::addByKey (string $server_key, string $key, mixed $value [, int $expiration])

# add an element under a new key on the specified server

12. Public bool Memcached::touch (string $key, int $expiration)

# set a new expiration time for key

13. Public bool Memcached::touchByKey (string $server_key, string $key, int $expiration)

# set expiration time for key in specified server

14. Public bool Memcached::append (string $key, string $value)

# append the string value corresponding to the value parameter to the existing element

Note: if the Memcached::OPT_COMPRESSION constant is turned on, this operation will fail with a warning because appending data to compressed data may result in unzipped data.

15. Public bool Memcached::appendByKey (string $server_key, string $key, string $value)

# append the string value corresponding to the value parameter to the element that already exists on the specified server

16. Public bool Memcached::prepend (string $key, string $value)

# append data to an existing element

Public bool Memcached::prependByKey (string $server_key, string $key, string $value)

# append the string value corresponding to the value parameter to the element that already exists on the specified server

18. Public bool Memcached::replace (string $key, mixed $value [, int $expiration])

# replace elements that already exist under key

19. Public bool Memcached::replaceByKey (string $server_key, string $key, mixed $value [, int $expiration])

# replace the elements under the key of the specified server

20. Public int Memcached::decrement (string $key [int $offset = 1])

# decrease the value of a numeric element

# there is no key return error, reduced to less than 0, the result is 0, the element is not a numeric value and is treated as 0

21. Public int Memcached::decrementByKey (string $server_key, string $key [, int $offset = 1 [, int $initial_value = 0 [, int $expiry = 0]])

# specifies that the server reduces the value of the numeric element, and the key that does not exist is initialized to 0

22. Public int Memcached::increment (string $key [, int $offset = 1])

# increase the value of numeric elements

23. Public int Memcached::incrementByKey (string $server_key, string $key [, int $offset = 1 [, int $initial_value = 0 [, int $expiry = 0]])

# ditto

24. Public bool Memcached::delete (string $key [, int $time = 0])

# Delete an element

# after setting the time, it is not deleted until after the time time, during which the get, add and replace commands are not valid for the key.

25. Public bool Memcached::deleteByKey (string $server_key, string $key [, int $time = 0])

# ditto

26. Public bool Memcached::deleteMulti (array $keys [, int $time = 0])

# Delete multiple key

27. Public bool Memcached::deleteMultiByKey (string $server_key, array $keys [, int $time = 0])

# ditto

28. Public bool Memcached::flush ([int $delay = 0])

# invalidate the data of all buffers

29. Public mixed Memcached::get (string $key [, callback $cache_cb [, float & $cas_token]])

# retrieve an element

# $callback callback function. If there is no value of $key, this function will be called, passing in three parameters, memcache object, key, and the return value of the reference passing variable (returned when true)

# $cas_token is used with cas. The last get of the same client will generate a 64-bit unique identifier store, then use cas to view the changes, and return false if modified by another client in the process

30. Public mixed Memcached::getByKey (string $server_key, string $key [, callback $cache_cb [, float & $cas_token]])

# retrieve elements from a specific server

31. Public mixed Memcached::getMulti (array $keys [, array & $cas_tokens [, int $flags]])

# retrieve multiple elements and provide a case value, then add a case value

# $flags can only be Memcached::GET_PRESERVE_ORDER, which ensures that the order of returned key is the same as that of the request.

32. Public array Memcached::getMultiByKey (string $server_key, array $keys [, string & $cas_tokens [, int $flags]])

# retrieve multiple elements from a specific server

33. Public array Memcached::getAllKeys (void)

# Gets the keys stored on all the servers

34. Public bool Memcached::getDelayed (array $keys [, bool $with_cas [, callback $value_cb]])

# request keys from the server. This method does not wait for a response but immediately returns bool. Fetch and fetchAll are used to collect results.

When # $with_cas true, the cascas value is recorded at the same time

# $value_cb result callback function processing

35. Public bool Memcached::getDelayedByKey (string $server_key, array $keys [, bool $with_cas [, callback $value_cb]])

# request multiple keys from the specified server

36. Public array Memcached::fetch (void)

# grab the next result from the last request.

37. Public array Memcached::fetchAll (void)

# grab all remaining results

38. Public mixed Memcached::getOption (int $option)

# get the option value of Memcached

One of the # OPT_* series constants.

39. Public bool Memcached::setOption (int $option, mixed $value)

# set a memcached option

40. Public bool Memcached::setOptions (array $options)

# set multiple memcached options

41. Public int Memcached::getResultCode (void)

# return the result code of the last operation

42. Public string Memcached::getResultMessage (void)

# return the result description message of the last operation

43. Public array Memcached::getServerByKey (string $server_key)

# get the server information mapped by key

44. Public array Memcached::getServerList (void)

# get the server table in the server pool

45. Public array Memcached::getStats (void)

# get statistics in the server pool

46. Public array Memcached::getVersion (void)

# get the version information of all servers in the server pool

47, public bool Memcached::isPersistent (void)

# Test whether the server is permanently connected

48, public bool Memcached::isPristine (void)

# Test whether memcache has been created recently

49. Public bool Memcached::quit (void)

# close the connection

50. Public bool Memcached::resetServerList (void)

# reset server service information for all servers

Public void Memcached::setSaslAuthData (string $username, string $password)

# Set the credentials to use for authentication

After reading the above, have you mastered the methods of php memcached? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report