/**
  * Increment a Redis counter by the amount specified
  *
  * @param  string $key
  * @param  int    $offset
  * @param  string $group
  * @return bool
  */
 public function increment($key, $offset = 1, $group = 'default')
 {
     $derived_key = $this->build_key($key, $group);
     $offset = (int) $offset;
     // If group is a non-Redis group, save to internal cache, not Redis
     if (in_array($group, $this->no_redis_groups) || !$this->redis_status()) {
         $value = $this->get_from_internal_cache($derived_key, $group);
         $value += $offset;
         $this->add_to_internal_cache($derived_key, $value);
         return true;
     }
     // Save to Redis
     $result = $this->parse_predis_response($this->redis->incrBy($derived_key, $offset));
     $this->add_to_internal_cache($derived_key, (int) $this->redis->get($derived_key));
     return $result;
 }
Esempio n. 2
0
<?php

require 'Predis/Autoloader.php';
Predis\Autoloader::register();
$redis = new Predis\Client(array('host' => '127.0.0.1'));
$redis->set('counter', 0);
$redis->incrBy('counter', 7);
$counter = $redis->get('counter');
print $counter;