示例#1
0
 /**
  * 递增
  * @param string $key   键名
  * @param int $step     递增步长
  * @return int|false    递增后的值,失败返回false
  */
 public function incr($key, $step = 1)
 {
     if ($this->driver->checkDriver()) {
         if (method_exists($this->driver, 'incr')) {
             return $this->driver->incr($key, $step);
         } else {
             if (!is_int($step)) {
                 return false;
             }
             $value = $this->driver->get($key);
             if ($value !== false && !is_int($value)) {
                 return false;
             }
             if ($this->driver->set($key, $value += $step)) {
                 return $value;
             }
             return false;
         }
     }
     if ($this->driver->isFallback() && $this->type !== self::$config['fallback']) {
         return $this->driver->backup()->incr($key, $step);
     }
     return false;
 }