PHP methods for Memcached operations and phpmemcached Methods

Source: Internet
Author: User

PHP methods for Memcached operations and phpmemcached Methods

 

For the non-relational database installation of memcached, the extension installation of memcache in php, And the extension installation of memcached in php, refer:

Http://www.cnblogs.com/phpstudy2015-6/p/6670103.html

(1) memcache Extension

1. boolMemcache: set(String$key, Mixed$var[, Int$flag[, Int$expire])

# If the Key exists, update the value. If the Key does not exist, set the k-v pair. Note: $ var can store any data

2. boolMemcache: add(String$key, Mixed$var[, Int$flag[, Int$expire])

# Add a key only when the key does not exist

3. boolMemcache: replace(String$key, Mixed$var[, Int$flag[, Int$expire])

# Replace the existing key value. If the key does not exist, an error is returned.

4. stringMemcache: get(String$key[, Int&$flags])

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

# Obtain one or more values

5. boolMemcache: delete(String$key[, Int$timeout= 0])

# Delete the key element. The number of seconds after timeout is set.

# [Note] Using timeout for memcached in some versions will cause deletion failure (0 is acceptable)

6. intMemcache: increment(String$key[, Int$value= 1])

# If the key exists and can be converted to a number, an int is added; otherwise, the key is directly replaced with a value. If the key does not exist, false is returned.

7. intMemcache: decrement(String$key[, Int$value= 1])

8. boolMemcache: flush(Void)

# All elements are invalid.

9. boolMemcache: connect(String$host[, Int$port[, Int$timeout=1])

# Connect to the memcache server. After the script is executed, it will be automatically closed (close can be used to automatically close it)

10. boolMemcache: close(Void)

# Disable the memcache Link (this function will not close persistent connections)

11. mixedMemcache: pconnect(String$host[, Int$port[, Int$timeout])

# Establishing persistent connections

12. boolMemcache: 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 in this method will be closed or closed when the script ends.

# Using this method, the network connection is not necessarily connected immediately, but will be connected only when the server is used. Therefore, even if a large number of servers are added to the connection pool, there is no overhead.

Parameters:

$persistent   Persistence or not. The default value is true.

$weight   Weight

$retry_interval   The retry time when the server connection fails. The default value is 15 seconds.-1 indicates no retry.

$ Status controls whether the server is marked as online (if the connection fails, a server is missing from the connection pool, which will affect the original allocation algorithm)

$failure_callback   Functions executed after connection failure (executed before failover), including two parameters: host and port

13. arrayMemcache: getExtendedStats([String$type[, Int$slabid[, Int$limit= 100])

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

# GetExtendedStats ('slabs ') obtains the id of active slabs blocks on each server.

# GetExtendedStats ('cachedump ', $ slabid, $ limit) Get the items cached in each slab

Parameters:

# Type indicates the type of statistics to be captured. The values available include {reset, malloc, maps, cachedump, slabs, items, sizes}

# Slabid is used with ParameterstypeWhen you copy data from a specified slab in blocks, the cachedump command occupies the server and is usually used for strict debugging.

# Limit is used for and ParametertypeSets the number of objects retrieved from the server when cachedump is used together.

14. intMemcache: getServerStatus(String$host[, Int$port= 11211])

# Return the status of a server. "0" indicates that the server is offline, and "0" indicates that the server is online.

15. arrayMemcache: getStats([String$type[, Int$slabid[, Int$limit= 100])

#GetStats ()ReturnServer statistics of an associated data. Same as above

16. stringMemcache: getVersion(Void)

# Returns the version number.

17. boolMemcache: setCompressThreshold(Int$threshold[, Float$min_savings])

# Enable automatic compression for shards

Parameters:

# Threshold controls the threshold for automatic compression of Multiple shards.

# Min_saving specifies the compression ratio of the actually stored values after compression. The supported values must be between 0 and 1. The default value is 0.2, indicating 20% compression rate.

18. boolMemcache: setServerParams(String$host[, Int$port= 11211 [, int$timeout[, Int$retry_interval= False [, bool$status[, Callback$failure_callback])

# Used to modify server parameters during runtime

# Same as above

 

(2) memcached Extension

1,Memcached ::__ construct([String$persistent_id])

# By default, the Memcached instance will be destroyed after the request ends. However, you can usepersistent_idSpecify a unique ID for each instance and share the instance among requests. Allpersistent_idThe instance created with the same value shares the same connection.

<?php
# Create a Common Object
$m1 = new Memcached();
echo get_class($m);

/* Create a Persistent Object */
$m2 = new Memcached('story_pool');
$m3 = new Memcached('story_pool');

# Now $ m2 and $ m3 share the same connection. You can use isPresistent for detection.
?>

2. public boolMemcached: addServer(String$host, Int$port[, Int$weight= 0])

# Add a specified server to the server pool. No connection is established with the server.

3. public boolMemcached: addServers(Array$servers)

# Add multiple servers to the Service pool

4. public boolMemcached: cas(Float$cas_token, String$key, Mixed$value[, Int$expiration])

# Perform the "check and set" operation.Last time of current clientIf the value corresponding to the key is not modified by other clients, the value can be written. Passcas_tokenParameter check

5. public boolMemcached: casByKey(Float$cas_token, String$server_key, String$key, Mixed$value[, Int$expiration])

# Specify the server, same as above

# [$ Server_key is also a common key. * The operation of ByKey series interfaces is as follows: first, hash $ server_key to get the server where $ server_key should be stored, then perform the corresponding operation on the server where $ server_key is located]

6. public boolMemcached: set(String$key, Mixed$value[, Int$expiration])

# Store the value (the value can be any valid non-resource php type) under the key

7. public boolMemcached: setByKey(String$server_key, String$key, Mixed$value[, Int$expiration])

# Specify the server, same as above

8. public boolMemcached: setMulti(Array$items[, Int$expiration])

# Store multiple elements

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

9. public boolMemcached: setMultiByKey(String$server_key, Array$items[, Int$expiration])

# Specify the server, same as above

10. public boolMemcached: add(String$key, Mixed$value[, Int$expiration])

# Adding an element to a new key fails if the key exists.

11. public boolMemcached: addByKey(String$server_key, String$key, Mixed $value[, Int$expiration])

# Add an element to a new key on the specified server

12. public boolMemcached: touch(String$key, Int$expiration)

# Set a new expiration time for the key

13. public boolMemcached: touchByKey(String$server_key, String$key, Int$expiration)

# Set the expiration time for the key on the specified server

14. public boolMemcached: append(String$key, String$value)

# Append an existing elementvalueString value corresponding to the parameter

NOTE: If Memcached: OPT_COMPRESSION is enabled, this operation will fail and a warning will be triggered, because appending data to the compressed data may cause unzipping.

<?php

$a= new Memcached();

$a->addServer('192.168.95.11',11211);

#$a->addServer('192.168.95.11',11210);

#$a->setOption(Memcached::OPT_COMPRESSION,false);

$b=$a->append('e','popop');

echo"<pre>";

print_r($b);

echo"</pre>";die;

?>

15. public boolMemcached: appendByKey(String$server_key, String$key, String$value)

# Append an existing element to the specified servervalueString value corresponding to the parameter

16. public boolMemcached: prepend(String$key, String$value)

# Append data to an existing element

17. public boolMemcached: prependByKey(String$server_key, String$key, String$value)

# Append an existing element to the specified servervalueString value corresponding to the parameter

18. public boolMemcached: replace(String$key, Mixed$value[, Int$expiration])

# Replace an element with an existing key

19. public boolMemcached: replaceByKey(String$server_key, String$key, Mixed$value[, Int$expiration])

# Replace the elements under the key of the specified server

20. public intMemcached: decrement(String$key[, Int$offset= 1])

# Reduce the value of a numeric Element

# If the key does not exist, an error is returned. If the value is reduced to less than 0, the result is 0. If the element is not a value, the value 0 is used.

21. public intMemcached: decrementByKey(String$server_key, String$key[, Int$offset= 1 [, int$initial_value= 0 [, int$expiry= 0])

# Specify the server to reduce the value of the numeric element. If the key does not exist, the value is initialized to 0.

22. public intMemcached: increment(String$key[, Int$offset= 1])

# Adding the value of a numeric Element

23. public intMemcached: incrementByKey(String$server_key, String$key[, Int$offset= 1 [, int$initial_value= 0 [, int$expiry= 0])

# Same as above

24. public boolMemcached: delete(String$key[, Int$time= 0])

# Deleting an element

# After the time is set, it indicates that the key is deleted only after the time. During this time, the get, add, and replace commands are invalid for this key.

25. public boolMemcached: deleteByKey(String$server_key, String$key[, Int$time= 0])

# Same as above

26. public boolMemcached: deleteMulti(Array$keys[, Int$time= 0])

# Deleting multiple keys

27. public boolMemcached: deleteMultiByKey(String$server_key, Array$keys[, Int$time= 0])

# Same as above

28. public boolMemcached: flush([Int$delay= 0])

# Invalidate data in all Buffers

29. public mixedMemcached: get(String$key[, Callback$cache_cb[, Float&$cas_token])

# Retrieving an element

# $ Callback function. If the value of $ key does not exist, this function will be called. Three memcache objects, keys, and the return values of the referenced variables will be passed in (returned if true)

# $ Cas_token is used with cas. The last get of the same client will generate a 64-bit unique identifier storage, and then use cas to view the changes. If this process is modified by other clients, false is returned.

30. public mixedMemcached: getByKey(String$server_key, String$key[, Callback$cache_cb[, Float&$cas_token])

# Retrieving elements from a specific server

31. public mixedMemcached: getMulti(Array$keys[, Array&$cas_tokens[, Int$flags])

# Search for multiple elements. If the $ cas value is provided, add the cas value.

# $ Flags can only be Memcached: GET_PRESERVE_ORDER. Ensure that the returned key is in the same order as the request.

32. public arrayMemcached: getMultiByKey(String$server_key, Array$keys[, String&$cas_tokens[, Int$flags])

# Retrieving multiple elements from a specific server

33. public arrayMemcached: getAllKeys(Void)

# Gets the keys stored on all the servers

34. public boolMemcached: getDelayed(Array$keys[, Bool$with_cas[, Callback$value_cb])

# Request keys from the server. This method returns bool immediately instead of waiting for a response.

# $ With_cas true indicates that the cas value is recorded simultaneously

#$value_cb     Result callback function processing

35. public boolMemcached: getDelayedByKey(String$server_key, Array$keys[, Bool$with_cas[, Callback$value_cb])

# Request multiple keys from the specified server

36. public arrayMemcached: fetch(Void)

# Capture the next result from the last request.

37. public arrayMemcached: fetchAll(Void)

# Capture all remaining results

38. public mixedMemcached: getOption(Int$option)

# Obtain the option value of Memcached

# One of the OPT _ * series constants.

39. public boolMemcached: setOption(Int$option, Mixed$value)

# Set a memcached Option

40. public boolMemcached: setOptions(Array$options)

# Set multiple memcached options

41. public intMemcached: getResultCode(Void)

# Return the result code of the last operation

42. public stringMemcached: getResultMessage(Void)

# Return the result description message of the last operation

43. public arrayMemcached: getServerByKey(String$server_key)

# Obtain the server information mapped to the key

44. public arrayMemcached: getServerList(Void)

# Obtain the server table in the server pool

45. public arrayMemcached: getStats(Void)

# Getting statistics in the server pool

46. public arrayMemcached: getVersion(Void)

# Retrieve all server version information in the server pool

47. public boolMemcached: isPersistent(Void)

# Test whether the server is permanently connected

48. public boolMemcached: isPristine(Void)

# Test whether memcache has been recently created

49. public boolMemcached: quit(Void)

# Closing a connection

50. public boolMemcached: resetServerList(Void)

# Resetting Server service information for all servers

51. public voidMemcached: setSaslAuthData(String$username, String$password)

# Set the credentials to use for authentication

 

(The above are the notes you have prepared when learning memcached in the reference manual. By the way, you can also paste them out. If there are any shortcomings or errors, please point them out)

Author: The leaf goes with the wind

 

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.