/** * Decrement the number stored at key by one. * * @param string $key * * @return int the new value * @link http://redis.io/commands/decr * @example * <pre> * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1 * $redis->decr('key1'); // -2 * $redis->decr('key1'); // -3 * </pre> */ public function decr($key) { try { return $this->client->decr($key); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Test decrementing a key */ public function testDecr() { $this->redis->del('testDecr'); $this->assertEquals(-1, $this->redis->decr('testDecr')); $this->assertEquals(-1, $this->redis->get('testDecr')); $this->assertEquals(-2, $this->redis->decr('testDecr')); $this->assertEquals(-2, $this->redis->get('testDecr')); $this->assertEquals(-3, $this->redis->decr('testDecr')); $this->assertEquals(-3, $this->redis->get('testDecr')); $this->assertInternalType('int', $this->redis->decr('testDecr')); }
/** * {@inheritdoc} */ public function decr($key) { unset($this->cache[$key]); return $this->redis->decr($key); }