PHP - Memcache::decrement() Function
Memcache::decrement() function can decrement the item's value.
Syntax
int Memcache::decrement( string $key [, int $value = 1 ] )
Memcache::decrement() function can decrement the value of an item by value. Similar to the Memcache::increment() function, the current value of an item is being converted to numerical and after that value is subtracted.
Note: A new item's value cannot be less than zero, and do not use the Memcache::decrement() function with an item that was stored compressed because a consequent call to the Memcache::get() function can fail.
Memcache::decrement() function can return item's new value on success or false on failure.
Example
<?php
/* procedural API */
$memcache_obj = memcache_connect("memcache_host", 11211);
/* decrement item by 2 */
$new_value = memcache_decrement($memcache_obj, "test_item", 2);
/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect("memcache_host", 11211);
/* decrement item by 3 */
$new_value = $memcache_obj->decrement("test_item", 3);
?>
Advertisements