当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::incrBy方法代码示例

本文整理汇总了PHP中Redis::incrBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::incrBy方法的具体用法?PHP Redis::incrBy怎么用?PHP Redis::incrBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::incrBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: increment

 public static function increment($host)
 {
     $count = self::$redis->incrBy(self::$prefix . $host, 1);
     if (self::$redis->get(self::$prefix . $host) == 1) {
         self::$redis->setTimeout(self::$prefix . $host, self::$ttl);
     }
     return $count;
 }
开发者ID:ariarijp,项目名称:cassowary,代码行数:8,代码来源:RedisAdapter.php

示例2: incr

 public function incr($key, $offset = 1, $group = 'default')
 {
     if (empty($group)) {
         $group = 'default';
     }
     if ($this->_connected && !in_array($group, $this->_no_redis_groups)) {
         try {
             $this->_redis->incrBy($this->_get_redis_key($key, $group), $offset);
         } catch (Exception $e) {
             $this->_connected = false;
             return false;
         }
         if (!$this->_exists($key, $group)) {
             $this->get($key, $group);
         } else {
             $this->_cache[$this->_get_prefix($group)][$group][$key] += $offset;
         }
     } else {
         if (!$this->_exists($key, $group)) {
             $this->_cache[$this->_get_prefix($group)][$group][$key] = 0;
         }
         $this->_cache[$this->_get_prefix($group)][$group][$key] += $offset;
     }
     return true;
 }
开发者ID:shtrihstr,项目名称:redis-object-cache,代码行数:25,代码来源:object-cache.php

示例3: increment

 /**
  * Increases the value
  *
  * @param   string $key
  * @param   int $value
  * @return  void
  */
 public function increment($key, $value = 1)
 {
     if ($value == 1) {
         $this->_redis->incr($this->_prefix . $key);
     } else {
         $this->_redis->incrBy($this->_prefix . $key, $value);
     }
 }
开发者ID:melihucar,项目名称:lime-cache,代码行数:15,代码来源:RedisDriver.php

示例4: incrBy

 public function incrBy($chiave, $valore = 1, $scadenza = Cache::SCADENZA_DEFAULT)
 {
     $x = parent::incrBy($chiave, $valore);
     if ($scadenza) {
         parent::expire($chiave, $scadenza);
     }
     return $x;
 }
开发者ID:pizar,项目名称:gaia,代码行数:8,代码来源:Cache.php

示例5: incrBy

	public function incrBy($key='', $count='') {
		try {
			return $this->_redis->incrBy($key, $count);
		} catch (Exception $e) {
			$this->_error = $e->getMessage();
			return false;
		}
	}
开发者ID:neil-chen,项目名称:NeilChen,代码行数:8,代码来源:RedisCache.class.php

示例6: testDifferentTypeHash

 public function testDifferentTypeHash()
 {
     $key = '{hash}hash';
     $dkey = '{hash}hash';
     $this->redis->del($key);
     $this->assertEquals(1, $this->redis->hSet($key, 'key', 'value'));
     // string I/F
     $this->assertEquals(FALSE, $this->redis->get($key));
     $this->assertEquals(FALSE, $this->redis->getset($key, 'value2'));
     $this->assertEquals(FALSE, $this->redis->append($key, 'append'));
     $this->assertEquals(FALSE, $this->redis->getRange($key, 0, 8));
     $this->assertEquals(array(FALSE), $this->redis->mget(array($key)));
     $this->assertEquals(FALSE, $this->redis->incr($key));
     $this->assertEquals(FALSE, $this->redis->incrBy($key, 1));
     $this->assertEquals(FALSE, $this->redis->decr($key));
     $this->assertEquals(FALSE, $this->redis->decrBy($key, 1));
     // lists I/F
     $this->assertEquals(FALSE, $this->redis->rPush($key, 'lvalue'));
     $this->assertEquals(FALSE, $this->redis->lPush($key, 'lvalue'));
     $this->assertEquals(FALSE, $this->redis->lLen($key));
     $this->assertEquals(FALSE, $this->redis->lPop($key));
     $this->assertEquals(FALSE, $this->redis->lrange($key, 0, -1));
     $this->assertEquals(FALSE, $this->redis->lTrim($key, 0, 1));
     $this->assertEquals(FALSE, $this->redis->lGet($key, 0));
     $this->assertEquals(FALSE, $this->redis->lSet($key, 0, "newValue"));
     $this->assertEquals(FALSE, $this->redis->lrem($key, 'lvalue', 1));
     $this->assertEquals(FALSE, $this->redis->lPop($key));
     $this->assertEquals(FALSE, $this->redis->rPop($key));
     $this->assertEquals(FALSE, $this->redis->rPoplPush($key, $dkey . 'lkey1'));
     // sets I/F
     $this->assertEquals(FALSE, $this->redis->sAdd($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->srem($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sPop($key));
     $this->assertEquals(FALSE, $this->redis->sMove($key, $dkey . 'skey1', 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->scard($key));
     $this->assertEquals(FALSE, $this->redis->sismember($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sInter($key, $dkey . 'skey2'));
     $this->assertEquals(FALSE, $this->redis->sUnion($key, $dkey . 'skey4'));
     $this->assertEquals(FALSE, $this->redis->sDiff($key, $dkey . 'skey7'));
     $this->assertEquals(FALSE, $this->redis->sMembers($key));
     $this->assertEquals(FALSE, $this->redis->sRandMember($key));
     // sorted sets I/F
     $this->assertEquals(FALSE, $this->redis->zAdd($key, 1, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zRem($key, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zIncrBy($key, 1, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zRank($key, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zRevRank($key, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zRange($key, 0, -1));
     $this->assertEquals(FALSE, $this->redis->zRevRange($key, 0, -1));
     $this->assertEquals(FALSE, $this->redis->zRangeByScore($key, 1, 2));
     $this->assertEquals(FALSE, $this->redis->zCount($key, 0, -1));
     $this->assertEquals(FALSE, $this->redis->zCard($key));
     $this->assertEquals(FALSE, $this->redis->zScore($key, 'zValue1'));
     $this->assertEquals(FALSE, $this->redis->zRemRangeByRank($key, 1, 2));
     $this->assertEquals(FALSE, $this->redis->zRemRangeByScore($key, 1, 2));
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:56,代码来源:RedisTest.php

示例7: increment

 /**
  * {@inheritdoc}
  */
 public function increment($key, $value = 1)
 {
     if ($value < 1) {
         throw new \InvalidArgumentException('Value of incrementation must be greater that nil.');
     }
     if ($value === 1) {
         return $this->redis->incr($key);
     }
     return $this->redis->incrBy($key, $value);
 }
开发者ID:lingualeo,项目名称:php-cache,代码行数:13,代码来源:RedisCache.php

示例8: incrBy

 /**
  * @param string $key
  * @param string $value = 1
  * @return int
  */
 public function incrBy($key, $value = 1)
 {
     try {
         $this->_useCnt++;
         return parent::incrBy($key, $value);
     } catch (Exception $e) {
         Wk::logger()->err($e->getMessage());
     }
     return 0;
 }
开发者ID:telander,项目名称:waka,代码行数:15,代码来源:Wk_Redis.php

示例9: calculation

 /**
  * Perform a calculation.
  *
  * @param string $key
  * @param int|float $byHowMuch
  * @param string $type
  * @return $this
  * @throws \Exception
  */
 private function calculation($key, $byHowMuch, $type)
 {
     $byHowMuch = $byHowMuch === false ? 1 : $byHowMuch;
     if ($this->exists($key)) {
         $result = $type == "add" ? $this->redis->incrBy($key, $byHowMuch) : $this->redis->decrBy($key, $byHowMuch);
         if ($result === false) {
             throw new \Exception("This value can not be used in calculations");
         }
     } else {
         throw new \Exception("You can not perform calculations from a value which is not set.");
     }
     return $this;
 }
开发者ID:NeilMasters,项目名称:RedisHelper,代码行数:22,代码来源:RedisHelper.php

示例10: testIncr

 public function testIncr()
 {
     $this->redis->set('key', 0);
     $this->redis->incr('key');
     $this->assertEquals(1, (int) $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertEquals(2, (int) $this->redis->get('key'));
     $this->redis->incr('key', 3);
     $this->assertEquals(5, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', 3);
     $this->assertEquals(8, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', 1);
     $this->assertEquals(9, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', -1);
     $this->assertEquals(8, (int) $this->redis->get('key'));
     $this->redis->delete('key');
     $this->redis->set('key', 'abc');
     $this->redis->incr('key');
     $this->assertTrue("abc" === $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertTrue("abc" === $this->redis->get('key'));
 }
开发者ID:rjack,项目名称:phpredis,代码行数:22,代码来源:TestRedis.php

示例11: testIncr

 public function testIncr()
 {
     $this->redis->set('key', 0);
     $this->redis->incr('key');
     $this->assertEquals(1, (int) $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertEquals(2, (int) $this->redis->get('key'));
     $this->redis->incr('key', 3);
     $this->assertEquals(5, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', 3);
     $this->assertEquals(8, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', 1);
     $this->assertEquals(9, (int) $this->redis->get('key'));
     $this->redis->incrBy('key', -1);
     $this->assertEquals(8, (int) $this->redis->get('key'));
     $this->redis->delete('key');
     $this->redis->set('key', 'abc');
     $this->redis->incr('key');
     $this->assertTrue("abc" === $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertTrue("abc" === $this->redis->get('key'));
     // incrbyfloat
     $this->redis->delete('key');
     $this->redis->set('key', 0);
     $this->redis->incrbyfloat('key', 1.5);
     $this->assertEquals('1.5', $this->redis->get('key'));
     $this->redis->incrbyfloat('key', 2.25);
     $this->assertEquals('3.75', $this->redis->get('key'));
     $this->redis->incrbyfloat('key', -2.25);
     $this->assertEquals('1.5', $this->redis->get('key'));
     $this->redis->set('key', 'abc');
     $this->redis->incrbyfloat('key', 1.5);
     $this->assertTrue("abc" === $this->redis->get('key'));
     $this->redis->incrbyfloat('key', -1.5);
     $this->assertTrue("abc" === $this->redis->get('key'));
 }
开发者ID:0,项目名称:phpredis,代码行数:36,代码来源:TestRedis.php

示例12: increase

 /**
  * 给缓存值加上一个数
  *
  * @param string $key 缓存键
  * @param mix $value 增加的值
  */
 public function increase($key, $value = 1)
 {
     return $this->connect->incrBy($key, $value);
 }
开发者ID:ZhuJingfa,项目名称:HuiLib,代码行数:10,代码来源:Redis.php

示例13: deinc

 /**
  * key值自增或者自减
  * @param $key string key名
  * @param $type int 0:自减 1:自增 默认为1
  * @param $n int 自增步长 默认为1
  */
 public static function deinc($key, $type = 1, $n = 1)
 {
     $redis = new \Redis();
     $redis->connect(self::_HOST, self::_PORT);
     $return = null;
     $n = (int) $n;
     switch ($type) {
         case 0:
             if ($n == 1) {
                 $return = $redis->decr($key);
             } else {
                 if ($n > 1) {
                     $return = $redis->decrBy($key, $n);
                 }
             }
             break;
         case 1:
             if ($n == 1) {
                 $return = $redis->incr($key);
             } else {
                 if ($n > 1) {
                     $return = $redis->incrBy($key, $n);
                 }
             }
             break;
         default:
             $return = false;
             break;
     }
     $redis->close();
     $redis = null;
     return $return;
 }
开发者ID:skyshow,项目名称:ticket,代码行数:39,代码来源:MyRedis.class.php

示例14: Redis

<?php

$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->set('counter', 0);
$redis->incrBy('counter', 7);
$counter = $redis->get('counter');
print $counter;
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:8,代码来源:redis.php

示例15: increment

 /**
  * 递增
  * 与原始increment方法区别的是若不存指定KEY时返回false,这个会自动递增
  *
  * @param string $key
  * @param int $offset
  */
 public function increment($key, $offset = 1, $lifetime = 60)
 {
     return $this->_redis->incrBy($key, $offset);
 }
开发者ID:xiaodin1,项目名称:myqee,代码行数:11,代码来源:redis.class.php


注:本文中的Redis::incrBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。