You are here

function ad_memcache_decrement in Advertisement 6

Same name and namespace in other branches
  1. 5.2 cache/memcache/ad_cache_memcache.inc \ad_memcache_decrement()
  2. 5 cache/memcache/ad_cache_memcache.inc \ad_memcache_decrement()

Decrement a numerical value in memcache.

1 call to ad_memcache_decrement()
ad_cache_memcache_sync_ad in cache/memcache/ad_cache_memcache.module
Syncronize counts for given advertisement with database.

File

cache/memcache/ad_cache_memcache.inc, line 312
Memcache include.

Code

function ad_memcache_decrement($key, $value = 1) {
  $memcache = ad_memcache_init();
  $rc = $memcache
    ->decrement($key, $value);
  if ($rc === FALSE) {

    // We tried incrementing a counter that hasn't yet been initialized.
    $rc = $memcache
      ->set($key, $value);
    if ($rc === FALSE) {

      // Another process already initialized the counter, increment it.
      $rc = $memcache
        ->decrement($key);
    }
  }
  return $rc;
}