Class MemcachedManager

Description

Begin Document

Located in /classes/class_MemcachedManager.php (line 35)


	
			
Method Summary
MemcachedManager __construct ([string $persistentid = ''], [ $prefix = ''])
bool add (string $key, mixed $value, [int $expiration = 0])
bool addByKey (string $server_key, string $key, mixed $value, [int $expiration = 0])
void addKeyTags (string $key, string $tags)
void addMultiKeyTag (array $keys, string $tag)
bool addServer (string $host, int $port, int $weight)
bool addServers (array $servers)
bool append (string $key, string $value)
bool appendByKey (string $server_key, string $key, string $value)
bool cas (float $cas_token, string $key, mixed $value, [ $expiration = 0], int $expire)
bool casByKey (float $cas_token, string $server_key, string $key, mixed $value, [ $expiration = 0], int $expire)
void cleanDelete (array $array)
mixed decrement (string $key, [int $offset = 1])
bool delete (string $key, [int $timeout = 0])
bool deleteByKey (string $server_key, string $key, [int $timeout = 0])
void deleteKeyTags (string $key, string $tags)
void deleteMultiKeyTag (array $keys, string $tag)
mixed fetch ()
mixed fetchAll ()
void fetchKeyTags (string $key, string $tags)
bool flushmc ([int $delay = 0])
mixed get (string $key, [callback $cache_cb = NULL], [ &$cas_token = NULL], float $cas_token)
mixed getByKey (string $server_key, string $key, [callback $cache_cb = NULL], [ &$cas_token = NULL], float $cas_token)
bool getDelayed (array $keys, [bool $with_cas = TRUE], [callback $value_cb = NULL])
bool getDelayedByKey (string $server_key, array $keys, [bool $with_cas = TRUE], [callback $value_cb = NULL])
void getFailCallback ( $memc,  $item)
mixed getMulti (array $keys, [ &$cas_tokens = NULL], [int $flags = NULL], array $cas_tokens)
mixed getMultiByKey (string $server_key, array $keys, [ &$cas_tokens = NULL], [int $flags = NULL], string $cas_tokens)
mixed getOption (int $option)
int getResultCode ()
string getResultMessage ()
bool getServerByKey (string $server_key)
array getServerList ()
array getStats ()
array getVersion ()
mixed increment (string $key, [int $offset = 1])
bool prepend (string $key, string $value)
bool prependByKey (string $server_key, string $key, string $value)
bool replace (string $key, mixed $value, [int $expire = 0])
bool replaceByKey (string $server_key, string $key, mixed $value, [int $expire = 0])
void searchForKeys (string $tag)
bool set (string $key, mixed $value, [int $expire = 0])
bool setByKey ( $server_key, string $key, mixed $value, [int $expire = 0])
bool setMulti (array $items, [int $expiration = 0])
bool setMultiByKey (string $server_key, array $items, [int $expiration = 0])
bool setOption (int $option, mixed $value)
Methods
Constructor __construct (line 71)

Creates a Memcached instance representing the connection to the memcache servers.

  • access: public
MemcachedManager __construct ([string $persistentid = ''], [ $prefix = ''])
  • string $persistentid: By default the Memcached instances are destroyed at the end of the request. To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance. All instances created with the same persistent_id will share the same connection.
  • $prefix
add (line 158)

Add an item under a new key.

Similar to set, but the operation fails if the key already exists.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->add('mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key already exists.
  • access: public
bool add (string $key, mixed $value, [int $expiration = 0])
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expiration: Some storage commands involve sending an expiration value (relative to an item or to an operation requested by the client) to the server. In all such cases, the actual value sent may either be Unix time (number of seconds since January 1, 1970, as an integer), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the expiration value is larger than that, the server will consider it to be real Unix time value rather than an offset from current time. If the expiration value is 0 (the default), the item never expires (although it may be deleted from the server to make place for other items).
addByKey (line 201)

Add an item under a new key on a specific server.

Functionally equivalent to add, except that the free-form server_key can be used to map the key to a specific server. This is useful if you need to keep a bunch of related keys on a certain server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->addByKey('myserverkey''mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key already exists.
  • access: public
bool addByKey (string $server_key, string $key, mixed $value, [int $expiration = 0])
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expiration: The expiration time, defaults to 0. SEE: add() $expiration for more info.
addKeyTags (line 1387)

Add Tags to a Key.

For best results, you should namespace your tags. Start all your tags with something consistent, like: 'tag_', and then you can keep that patters going with tags like 'tag_user_', or 'tag_object_' etc. This will allow you to find things the easiest by _searchTags() to find all tags in that namespace. So tags like 'tag_user_peter', 'tag_user_janet', 'tag_user_john' can be searched with _searchTags('_user_') and all your users will be found.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','bar');
  4.  $mcd->addKeyTags('foo'array('tag1''tag2''tag3'));
  5.  $mcd->addKeyTags('foo''tag4');
  6.  ?>

  • access: public
void addKeyTags (string $key, string $tags)
  • string $key: Memcached Key
  • string $tags: Memcached Tag
addMultiKeyTag (line 1433)

Add Tag to a Multiple Keys.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','value1');
  4.  $mcd->set('bar','value2');
  5.  $mcd->addMultiKeyTag(array('foo''bar')'tag_info');
  6.  ?>

  • access: public
void addMultiKeyTag (array $keys, string $tag)
  • array $keys: Memcached Keys
  • string $tag: Memcached Tag
addServer (line 250)

Add a server to the server pool.

Adds the specified server to the server pool. No connection is established to the server at this time, but if you are using consistent key distribution option, some of the internal data structures will have to be updated. Thus, if you need to add multiple servers, it is better to use addServers as the update then happens only once. The same server may appear multiple times in the server pool, because no ( duplication checks are made. This is not advisable; instead, use the weight option to increase the selection weighting of this server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('mem1.domain.com'1121133);
  4.  ?>

  • return: Returns TRUE on success or FALSE on failure.
  • access: public
bool addServer (string $host, int $port, int $weight)
  • string $host: The hostname of the memcache server. If the hostname is invalid, data-related operations will set RES_HOST_LOOKUP_FAILURE result code.
  • int $port: The port on which memcache is running. Usually, this is 11211.
  • int $weight: The weight of the server relative to the total weight of all the servers in the pool. This controls the probability of the server being selected for operations. This is used only with consistent distribution option and usually corresponds to the amount of memory available to memcache on that server.
addServers (line 292)

Add multiple servers to the server pool.

Adds servers to the server pool. Each entry in servers is supposed to an array containing hostname, port, and, optionally, weight of the server. No connection is established to the servers at this time. The same server may appear multiple times in the server pool, because no duplication checks are made. This is not advisable; instead, use the weight option to increase the selection weighting of this server.

  1.  <?php
  2.     $mcd new MemcacheManager();
  3.      if(!count($mcd->getServerList())){
  4.          $servers array(
  5.              array('localhost'1121133),
  6.              array('localhost'1121233),
  7.              array('localhost'1121333)
  8.          );
  9.          $mcd->addServers($servers);
  10.      }
  11.  ?>

  • return: Returns TRUE on success or FALSE on failure.
  • access: public
bool addServers (array $servers)
  • array $servers: Array of the servers to add to the pool.
append (line 329)

Append data to an existing item.

Appends the given value string to the value of an existing item. The reason that value is forced to be a string is that appending mixed types is not well-defined. Note: If the OPT_COMPRESSION is enabled, the operation will fail and a warning will be issued, because appending compressed data to a value that is potentially already compressed is not possible.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->set('foo''abc');
  5.  $mcd->append('foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool append (string $key, string $value)
  • string $key: The key under which to store the value.
  • string $value: The string to append.
appendByKey (line 369)

Append data to an existing item on a specific server.

Functionally equivalent to append, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager('server_key');
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->setByKey('myserverkey''foo''abc');
  5.  $mcd->appendByKey('myserverkey''foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool appendByKey (string $server_key, string $key, string $value)
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key under which to store the value.
  • string $value: The string to append.
cas (line 414)

C.A.S. Compare and Swap an item.

Performs a "check and set" operation, so that the item will be stored only if no other client has updated it since it was last fetched by this client. The check is done via the cas_token parameter which is a unique 64-bit value assigned to the existing item by memcache. See the documentation for get methods for how to obtain this token. Note that the token is represented as a double due to the limitations of PHP's integer space.

  1.  <?php
  2.  $mcd new MemcacheManager('server_key');
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->setByKey('myserverkey''foo''abc');
  5.  $mcd->appendByKey('myserverkey''foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_DATA_EXISTS if the item you are trying to store has been modified since you last fetched it.
  • access: public
bool cas (float $cas_token, string $key, mixed $value, [ $expiration = 0], int $expire)
  • float $cas_token: Unique value associated with the existing item. Generated by memcache.
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
  • $expiration
casByKey (line 449)

C.A.S. Compare and Swap an item on a specific server.

Functionally equivalent to cas, except that the free-form server_key can be used to map the key to a specific server. This is useful if you need to keep a bunch of related keys on a certain server.

  1.  <?php
  2.  $mcd new MemcacheManager('server_key');
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->setByKey('myserverkey''foo''abc');
  5.  $mcd->appendByKey('myserverkey''foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_DATA_EXISTS if the item you are trying to store has been modified since you last fetched it.
  • access: public
bool casByKey (float $cas_token, string $server_key, string $key, mixed $value, [ $expiration = 0], int $expire)
  • float $cas_token: Unique value associated with the existing item. Generated by memcache.
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
  • $expiration
cleanDelete (line 1623)

Delete Keys and then any tags that might be saved

  1.  <?php
  2.  $mcd->set('foo','value1');
  3.  $mcd->set('bar','value2');
  4.  $mcd->addKeyTags('bar'array('tag_user_peter''tag_user_janet''tag_user_john'));
  5.  $mcd->addKeyTags('foo'array('tag_user_peter''tag_user_janet''tag_user_john'));
  6.  
  7.  $keys $mcd->searchForKeys('_user_');
  8.  $mcd->cleanDelete($keys);
  9.  ?>

  • access: public
void cleanDelete (array $array)
  • array $array: Keys and Tags to delete from database and memcache
decrement (line 481)

Decrement numeric item's value.

Decrements a numeric item's value by the specified offset. If the item's value is not numeric, it is treated as if the value were 0. If the operation would decrease the value below 0, the new value will be 0. decrement() will fail if the item does not exist.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->decrement('mykey1'5);
  5.  $mcd->decrement('mykey2');
  6.  ?>

  • return: Returns item's new value on success or FALSE on failure. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
mixed decrement (string $key, [int $offset = 1])
  • string $key: Key of the item do decrement.
  • int $offset: Decrement the item by value . Optional and defaults to 1.
delete (line 520)

Delete an item. Deletes the key from the server.

The time parameter is the amount of time in seconds (or Unix time until which) the client wishes the server to refuse add and replace commands for this key. For this amount of time, the item is put into a delete queue, which means that it won't possible to retrieve it by the get command, but add and replace command with this key will also fail (the set command will succeed, however). After the time passes, the item is finally deleted from server memory. The parameter time defaults to 0 (which means that the item will be deleted immediately and further storage commands with this key will succeed).

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->delete('mykey1'30);
  5.  $mcd->delete('mykey2');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
bool delete (string $key, [int $timeout = 0])
  • string $key: The key to be deleted.
  • int $timeout: The amount of time the server will wait to delete the item.
deleteByKey (line 550)

Delete an item from a specific server.

Functionally equivalent to delete, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->deleteByKey('server_key''mykey1'30);
  5.  $mcd->deleteByKey('server_key''mykey2');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
bool deleteByKey (string $server_key, string $key, [int $timeout = 0])
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key to be deleted.
  • int $timeout: The amount of time the server will wait to delete the item.
deleteKeyTags (line 1471)

Delete Tags from a Key

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','bar');
  4.  $mcd->addKeyTags('foo'array('tag1''tag2''tag3'));
  5.  $mcd->deleteKeyTags('foo'array('tag1''tag3'));
  6.  $mcd->deleteKeyTags('foo''tag2');
  7.  ?>

  • access: public
void deleteKeyTags (string $key, string $tags)
  • string $key: Memcached Key
  • string $tags: Memcached Tag
deleteMultiKeyTag (line 1517)

Delete Tag from Multiple Keys.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','value1');
  4.  $mcd->set('bar','value2');
  5.  $mcd->addKeyTags('bar'array('tag_user_peter''tag_user_janet''tag_user_john'));
  6.  $mcd->addKeyTags('foo'array('tag_user_peter''tag_user_janet''tag_user_john'));
  7.  $mcd->deleteMultiKeyTag(array('foo''bar')'tag_user_john');
  8.  ?>

  • access: public
void deleteMultiKeyTag (array $keys, string $tag)
  • array $keys: Memcached Keys
  • string $tag: Memcached Tag
fetch (line 587)

Fetch the next result.

Retrieves the next result from the last request.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'11211);
  4.  
  5.  $mcd->set('int'99);
  6.  $mcd->set('string''a simple string');
  7.  $mcd->set('array'array(1112));
  8.  
  9.  $mcd->getDelayed(array('int''array')true);
  10.  while ($result $mcd->fetch()) {
  11.      var_dump($result);
  12.  }
  13.  ?>

  • return: Returns the next result or FALSE otherwise. The getResultCode will return RES_END if result set is exhausted.
  • access: public
mixed fetch ()
fetchAll (line 615)

Fetch the next result.

Retrieves the next result from the last request.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'11211);
  4.  
  5.  $mcd->set('int'99);
  6.  $mcd->set('string''a simple string');
  7.  $mcd->set('array'array(1112));
  8.  
  9.  $mcd->getDelayed(array('int''array')true);
  10.  var_dump($mcd->fetchAll());
  11.  ?>

  • return: Returns the results or FALSE on failure. Use getResultCode if necessary.
  • access: public
mixed fetchAll ()
fetchKeyTags (line 1555)

Fetch Tags associated with a Key

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','bar');
  4.  $mcd->addKeyTags('foo'array('tag1''tag2''tag3'));
  5.  $mcd->addKeyTags('foo''tag4');
  6.  $mcd->deleteKeyTags('foo'array('tag1''tag3'));
  7.  print_r($mcd->fetchKeyTags('foo'));
  8.  ?>

  • access: public
void fetchKeyTags (string $key, string $tags)
  • string $key: Memcached Key
  • string $tags: Memcached Tag
flushmc (line 641)

Invalidate all items in the cache.

Invalidates all existing cache items immediately (by default) or after the delay specified. After invalidation none of the items will be returned in response to a retrieval command (unless it's stored again under the same key after Memcached::flush() has invalidated the items). The flush does not actually free all the memory taken up by the existing items; that will happen gradually as new items are stored.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->flushmc(10);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool flushmc ([int $delay = 0])
  • int $delay: Numer of seconds to wait before invalidating the items.
get (line 674)

Retrieve an item.

Returns the item that was previously stored under the key. If the item is found and cas_token variable is provided, it will contain the CAS token value for the item. See cas for how to use CAS tokens. Read-through caching callback may be specified via cache_cb parameter.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  echo $mcd->get('mykey1'NULLNULL);
  5.  ?>

  • return: Returns the value stored in the cache or FALSE otherwise. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
mixed get (string $key, [callback $cache_cb = NULL], [ &$cas_token = NULL], float $cas_token)
  • string $key: The key of the item to retrieve.
  • callback $cache_cb: Read-through caching callback or NULL. This callback handler will only get executed if the $key DOES NOT exist.
  • float $cas_token: The variable to store the CAS token in.
  • &$cas_token
getByKey (line 703)

Retrieve an item from a specific server.

Functionally equivalent to get, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  echo $mcd->getByKey('server_key''mykey1');
  5.  ?>

  • return: Returns the value stored in the cache or FALSE otherwise. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
mixed getByKey (string $server_key, string $key, [callback $cache_cb = NULL], [ &$cas_token = NULL], float $cas_token)
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key of the item to retrieve.
  • callback $cache_cb: Read-through caching callback or NULL.
  • float $cas_token: The variable to store the CAS token in.
  • &$cas_token
getDelayed (line 732)

Retrieve an item from a specific server.

Functionally equivalent to get, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->set('int'99);
  5.  $mcd->set('string''a simple string');
  6.  $mcd->set('array'array(1112));
  7.  echo $mcd->getDelayed(array('int''string''array')TRUENULL);
  8.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool getDelayed (array $keys, [bool $with_cas = TRUE], [callback $value_cb = NULL])
  • array $keys: Array of keys to request.
  • bool $with_cas: Whether to request CAS token values also.
  • callback $value_cb: The result callback or NULL.
getDelayedByKey (line 762)

Request multiple items from a specific server

Functionally equivalent to getDelayed, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->set('int'99);
  5.  $mcd->set('string''a simple string');
  6.  $mcd->set('array'array(1112));
  7.  echo $mcd->getDelayedByKey('server_key'array('int''string''array')TRUENULL);
  8.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool getDelayedByKey (string $server_key, array $keys, [bool $with_cas = TRUE], [callback $value_cb = NULL])
  • string $server_key: The key identifying the server to store the value on.
  • array $keys: Array of keys to request.
  • bool $with_cas: Whether to request CAS token values also.
  • callback $value_cb: The result callback or NULL.
getFailCallback (line 1744)

Default get callback handler

This is what is called if no other callback handler was used with get(). This only gets called when get failed to find the key you were looking for.

  • access: public
void getFailCallback ( $memc,  $item)
  • $memc
  • $item
getMulti (line 801)

Retrieve multiple items

Similar to get, but instead of a single key item, it retrievess multiple items the keys of which are specified in the keys array. If cas_tokens variable is provided, it is filled with the CAS token values for the found items. The flags parameter can be used to specify additional options for getMulti(). Currently, the only available option is Memcached::GET_PRESERVE_ORDER that ensures that the keys are returned in the same order as they were requested in. NOTE: Unlike get it is not possible to specify a read-through cache callback for getMulti(), because the memcache protocol does not provide information on which keys were not found in the multi-key request.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $items array(
  5.      'key1' => 'value1',
  6.      'key2' => 'value2',
  7.      'key3' => 'value3'
  8.  );
  9.  $mcd->setMulti($items);
  10.  $result $mcd->getMulti(array('key1''key3''badkey')$cas);
  11.  var_dump($result$cas);
  12.  ?>

  • return: Returns the array of found items or FALSE on failure. Use getResultCode if necessary.
  • access: public
mixed getMulti (array $keys, [ &$cas_tokens = NULL], [int $flags = NULL], array $cas_tokens)
  • array $keys: Array of keys to retrieve.
  • array $cas_tokens: The variable to store the CAS tokens for the found items.
  • int $flags: The flags for the get operation.
  • &$cas_tokens
getMultiByKey (line 840)

Retrieve multiple items from a specific server

functionally equivalent to getMulti, except that the free-form server_key can be used to map the keys to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $items array(
  5.      'key1' => 'value1',
  6.      'key2' => 'value2',
  7.      'key3' => 'value3'
  8.  );
  9.  $mcd->setMulti($items);
  10.  $result $mcd->getMultiByKey('server_key'array('key1''key3''badkey')$cas);
  11.  var_dump($result$cas);
  12.  ?>

  • return: Returns the array of found items or FALSE on failure. Use getResultCode if necessary.
  • access: public
mixed getMultiByKey (string $server_key, array $keys, [ &$cas_tokens = NULL], [int $flags = NULL], string $cas_tokens)
  • string $server_key: The key identifying the server to store the value on.
  • array $keys: Array of keys to retrieve.
  • string $cas_tokens: The variable to store the CAS tokens for the found items.
  • int $flags: The flags for the get operation.
  • &$cas_tokens
getOption (line 868)

Retrieve a Memcached option value

This method returns the value of a Memcached option. Some options correspond to the ones defined by libmemcached, and some are specific to the extension. See Memcached Constants for more information.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  var_dump($mcd->getOption(Memcached::OPT_COMPRESSION));
  4.  ?>

  • return: Returns the value of the requested option, or FALSE on error.
  • access: public
mixed getOption (int $option)
  • int $option: One of the Memcached::OPT_* constants. SEE: http://www.php.net/manual/en/memcached.constants.php
getResultCode (line 896)

Return the result code of the last operation

Returns one of the Memcached::RES_* constants that is the result of the last executed Memcached method.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->add('foo''bar');
  4.  if ($mcd->getResultCode(== Memcached::RES_NOTSTORED{
  5.      // my code
  6.  }
  7.  ?>

  • return: Result code of the last Memcached operation.
  • access: public
int getResultCode ()
getResultMessage (line 917)

Return the message describing the result of the last operation

Returns a string that describes the result code of the last executed Memcached method.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->add('foo''bar')// first time should succeed
  4.  $mcd->add('foo''bar');
  5.  echo $mcd->getResultMessage(),"\n";
  6.  ?>

  • return: Message describing the result of the last Memcached operation.
  • access: public
string getResultMessage ()
getServerByKey (line 947)

Map a key to a server

Returns the server that would be selected by a particular server_key in all the *ByKey() operations.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServers(array(
  4.      array('mem1.domain.com'1121140),
  5.      array('mem2.domain.com'1121140),
  6.      array('mem3.domain.com'1121120),
  7.  ));
  8.  
  9.  $mcd->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLEtrue);
  10.  
  11.  var_dump($mcd->getServerByKey('user'));
  12.  var_dump($mcd->getServerByKey('log'));
  13.  var_dump($mcd->getServerByKey('ip'));
  14.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool getServerByKey (string $server_key)
  • string $server_key: The key identifying the server to store the value on.
getServerList (line 974)

Get the list of the servers in the pool

Returns the list of all servers that are in its server pool.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('mem1.domain.com'1121133);
  4.  $mcd->addServer('mem1.domain.com'1121167);
  5.  ?>

  • return: Returns the list of all servers in the server pool.
  • access: public
array getServerList ()
getStats (line 995)

Get server pool statistics

Returns an array containing the state of all available memcache servers. See memcache protocol specification for details on these statistics.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  print_r($mcd->getStats());
  5.  ?>

  • return: Array of server statistics, one entry per server.
  • access: public
array getStats ()
getVersion (line 1015)

Get server pool version info

Returns an array containing the version info for all available memcache servers.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  print_r($mcd->getVersion());
  5.  ?>

  • return: Array of server versions, one entry per server.
  • access: public
array getVersion ()
increment (line 1037)

Increment item's value

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->increment('mykey1'5);
  5.  $mcd->increment('mykey2');
  6.  ?>

  • return: Returns new item's value on success or FALSE on failure. The getResultCode will return RES_NOTFOUND if the key does not exist.
  • access: public
mixed increment (string $key, [int $offset = 1])
  • string $key: Key of the item to increment
  • int $offset: Increment the item by value . Optional and defaults to 1.
prepend (line 1074)

Prepend data to an existing item

prepends the given value string to the value of an existing item. The reason that value is forced to be a string is that prepending mixed types is not well-defined. Note: If the OPT_COMPRESSION is enabled, the operation will fail and a warning will be issued, because appending compressed data to a value that is potentially already compressed is not possible.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->set('foo''abc');
  5.  $mcd->prepend('foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool prepend (string $key, string $value)
  • string $key: The key of the item to prepend the data to.
  • string $value: The string to prepend.
prependByKey (line 1114)

Prepend data to an existing item on a specific server

Functionally equivalent to prepend, except that the free-form server_key can be used to map the key to a specific server.

  1.  <?php
  2.  $mcd new MemcacheManager('server_key');
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->setByKey('myserverkey''foo''abc');
  5.  $mcd->prependByKey('myserverkey''foo''def');
  6.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool prependByKey (string $server_key, string $key, string $value)
  • string $server_key: The key identifying the server to store the value on.
  • string $key: The key of the item to prepend the data to.
  • string $value: The string to prepend.
replace (line 1152)

Replace the item under an existing key.

Similar to set, but the operation fails if the key does not exist on the server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->replace('mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool replace (string $key, mixed $value, [int $expire = 0])
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
replaceByKey (line 1186)

Replace the item under an existing key on a specific server

Functionally equivalent to replace, except that the free-form server_key can be used to map the key to a specific server. This is useful if you need to keep a bunch of related keys on a certain server.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->replaceByKey('server_key''mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. The getResultCode will return RES_NOTSTORED if the key does not exist.
  • access: public
bool replaceByKey (string $server_key, string $key, mixed $value, [int $expire = 0])
  • string $server_key: The key under which to store the value.
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
searchForKeys (line 1586)

Search for Namespaced Tag

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->set('foo','bar');
  4.  $mcd->addKeyTags('foo'array('tag_user_peter''tag_user_janet''tag_user_john'));
  5.  print_r($mcd->searchTag('_user_'));
  6.  ?>

  • access: public
void searchForKeys (string $tag)
  • string $tag: Namespaced Tag Search
set (line 1220)

Store an item.

Stores the value on a memcache server under the specified key. The expiration parameter can be used to control when the value is considered expired. The value can be any valid PHP type except for resources, because those cannot be represented in a serialized form. If the OPT_COMPRESSION option is turned on, the serialized value will also be compressed before storage.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->set('mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool set (string $key, mixed $value, [int $expire = 0])
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
setByKey (line 1256)

Store an item.

Stores the value on a memcache server under the specified key. The expiration parameter can be used to control when the value is considered expired. The value can be any valid PHP type except for resources, because those cannot be represented in a serialized form. If the OPT_COMPRESSION option is turned on, the serialized value will also be compressed before storage.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $mcd->setByKey('server_key''mykey1'$myarray130);
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool setByKey ( $server_key, string $key, mixed $value, [int $expire = 0])
  • string $key: The key under which to store the value.
  • mixed $value: The value to store.
  • int $expire: The expiration time, defaults to 0. SEE: add() $expiration for more info.
  • $server_key
setMulti (line 1294)

Store multiple items

Similar to set, but instead of a single key/value item, it works on multiple items specified in items. The expiration time applies to all the items at once.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $items array(
  5.      'key1' => 'value1',
  6.      'key2' => 'value2',
  7.      'key3' => 'value3'
  8.  );
  9.  $mcd->setMulti($items30);
  10.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool setMulti (array $items, [int $expiration = 0])
  • array $items: An array of key/value pairs to store on the server.
  • int $expiration: The expiration time, defaults to 0. SEE: add() $expiration for more info.
setMultiByKey (line 1329)

Store multiple items

Similar to set, but instead of a single key/value item, it works on multiple items specified in items. The expiration time applies to all the items at once.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->addServer('localhost'1121133);
  4.  $items array(
  5.      'key1' => 'value1',
  6.      'key2' => 'value2',
  7.      'key3' => 'value3'
  8.  );
  9.  $mcd->setMultiByKey('server_key'$items30);
  10.  ?>

  • return: Returns TRUE on success or FALSE on failure. Use getResultCode if necessary.
  • access: public
bool setMultiByKey (string $server_key, array $items, [int $expiration = 0])
  • string $server_key: The key identifying the server to store the value on.
  • array $items: An array of key/value pairs to store on the server.
  • int $expiration: The expiration time, defaults to 0. SEE: add() $expiration for more info.
setOption (line 1358)

Set a Memcached option

This method sets the value of a Memcached option. Some options correspond to the ones defined by libmemcached, and some are specific to the extension. See Memcached Constants for more information.

  1.  <?php
  2.  $mcd new MemcacheManager();
  3.  $mcd->setOption(Memcached::OPT_HASHMemcached::HASH_MURMUR);
  4.  $mcd->setOption(Memcached::OPT_PREFIX_KEY"widgets");
  5.  ?>

  • return: Returns TRUE on success or FALSE on failure.
  • access: public
bool setOption (int $option, mixed $value)
  • int $option: Memcached Option
  • mixed $value: Memcached Option Value

Documentation generated on Sat, 05 Dec 2009 00:54:59 -0600 by phpDocumentor 1.4.3