當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。