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


PHP Redis::incr方法代码示例

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


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

示例1: testIncr

 public function testIncr()
 {
     $this->redis->set('key', 0);
     $this->redis->incr('key');
     $this->assertEquals(1, $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertEquals(2, $this->redis->get('key'));
     $this->redis->incr('key', 3);
     $this->assertEquals(5, $this->redis->get('key'));
 }
开发者ID:hieutrieu,项目名称:phpredis,代码行数:10,代码来源:TestRedis.php

示例2: push

 /**
  * @see QueueInterface::push()
  */
 public function push(TaskInterface $task)
 {
     $eta = $task->getEta() ?: new \DateTime();
     $score = $eta->getTimestamp();
     $unique = $this->redis->incr('sequence');
     $member = $unique . '@' . $this->serializer->serialize($task);
     $result = $this->redis->zAdd('tasks', $score, $member);
     if (!$result) {
         throw new \RuntimeException(sprintf('Unable to push the task %s.', $task));
     }
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:14,代码来源:RedisQueue.php

示例3: execute

 /**
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return null
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $redisHost = $input->getOption('host');
     $redisPort = $input->getOption('port');
     $redisDb = $input->getOption('db');
     try {
         $config = Yaml::parse(file_get_contents($_SERVER['HOME'] . '/.hooks.yml'));
     } catch (\Exception $e) {
         $config = ['daemon' => ['host' => '127.0.0.1', 'port' => 6379, 'db' => 0]];
     }
     if ($redisHost) {
         $config['daemon']['host'] = $redisHost;
     }
     if ($redisPort) {
         $config['daemon']['port'] = $redisPort;
     }
     if ($redisDb) {
         $config['daemon']['db'] = $redisDb;
     }
     $redis = new \Redis();
     $redis->connect($config['daemon']['host'], $config['daemon']['port']);
     $redis->select($config['daemon']['db']);
     $version = $redis->incr('hooks.worker.version');
     $output->writeln('<info>Worker version incremented: ' . $version . '.</info>');
     return null;
 }
开发者ID:betacie,项目名称:hooks,代码行数:32,代码来源:WorkerIncrementCommand.php

示例4: 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

示例5: 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

示例6: incr

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

示例7: testDifferentTypeHash

 public function testDifferentTypeHash()
 {
     $key = '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->substr($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->lGetRange($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->lRemove($key, 'lvalue', 1));
     $this->assertEquals(FALSE, $this->redis->lPop($key));
     $this->assertEquals(FALSE, $this->redis->rPop($key));
     $this->assertEquals(FALSE, $this->redis->rPoplPush($key, __FUNCTION__ . 'lkey1'));
     // sets I/F
     $this->assertEquals(FALSE, $this->redis->sAdd($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sRemove($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sPop($key));
     $this->assertEquals(FALSE, $this->redis->sMove($key, __FUNCTION__ . 'skey1', 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sSize($key));
     $this->assertEquals(FALSE, $this->redis->sContains($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sInter($key, __FUNCTION__ . 'skey2'));
     $this->assertEquals(FALSE, $this->redis->sUnion($key, __FUNCTION__ . 'skey4'));
     $this->assertEquals(FALSE, $this->redis->sDiff($key, __FUNCTION__ . '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->zDelete($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->zReverseRange($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->zDeleteRangeByRank($key, 1, 2));
     $this->assertEquals(FALSE, $this->redis->zDeleteRangeByScore($key, 1, 2));
 }
开发者ID:rnamiki,项目名称:phpredis,代码行数:55,代码来源:TestRedis.php

示例8: testGetLastError

 public function testGetLastError()
 {
     // We shouldn't have any errors now
     $this->assertTrue($this->redis->getLastError() === NULL);
     // test getLastError with a regular command
     $this->redis->set('x', 'a');
     $this->assertFalse($this->redis->incr('x'));
     $incrError = $this->redis->getLastError();
     $this->assertTrue(strlen($incrError) > 0);
     // clear error
     $this->redis->clearLastError();
     $this->assertTrue($this->redis->getLastError() === NULL);
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:13,代码来源:RedisTest.php

示例9: clear

 /**
  * {@inheritdoc}
  */
 public function clear($key = null)
 {
     if (is_null($key)) {
         $this->redis->flushDB();
         return true;
     }
     $keyString = $this->makeKeyString($key, true);
     $keyReal = $this->makeKeyString($key);
     $this->redis->incr($keyString);
     // increment index for children items
     $this->redis->delete($keyReal);
     // remove direct item.
     $this->keyCache = array();
     return true;
 }
开发者ID:ehough,项目名称:stash,代码行数:18,代码来源:Redis.php

示例10: testIncr

 public function testIncr()
 {
     $this->redis->set('key', 0);
     $this->redis->incr('key');
     $this->assertEquals(1, $this->redis->get('key'));
     $this->redis->incr('key');
     $this->assertEquals(2, $this->redis->get('key'));
     $this->redis->incr('key', 3);
     $this->assertEquals(5, $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:virtulis,项目名称:phpredis,代码行数:16,代码来源:TestRedis.php

示例11: getByLock

 /**
  * 双重缓存,防止击穿 (如果key没有被初始化,仍有可能会导致击穿现象)
  * @param int  $key    Redis key
  * @return Mix
  */
 public function getByLock($key)
 {
     $sth = $this->redis->get($key);
     if ($sth === false) {
         return $sth;
     } else {
         $sth = json_decode($sth, true);
         if (intval($sth['expire']) <= time()) {
             $lock = $this->redis->incr($key . ".lock");
             if ($lock === 1) {
                 return false;
             }
             return $sth['data'];
         } else {
             return $sth['data'];
         }
     }
 }
开发者ID:WALES7CH,项目名称:TP-Admin,代码行数:23,代码来源:RedisHandler.class.php

示例12: queue_email

/**
 * Places an email into our email queue, to be sent later (normally within a second or so).
 * @param array $email
 * @param string $priority an unsigned integer as a string, between 0 and 10. Lower has higher priority, so 0 is highest priority.
 */
function queue_email($email, $priority = '9')
{
    $redis = new Redis();
    $host = '127.0.0.1';
    $port = 6379;
    $redis_connected = $redis->pconnect($host, $port);
    echo "Redis Connected: {$redis_connected}\n";
    if ($redis_connected) {
        $email_job = [];
        $email_job['priority.created'] = $priority . '.' . time();
        $email_job['data'] = json_encode($email);
        // Increase job index
        $email_job_index = $redis->incr('mail_sender:email_job_index');
        $email_job['job_id'] = $email_job_index;
        var_dump($email_job);
        // Insert job as an atomic transaction
        $redis->multi()->hMset("mail_sender:email_job:{$email_job_index}", $email_job)->zAdd("mail_sender:email_jobs", 0, $email_job_index)->exec();
    }
}
开发者ID:keeganbrown,项目名称:node-redis-priority-mail-queue,代码行数:24,代码来源:queue_email.php

示例13: testGetLastError

 public function testGetLastError()
 {
     // We shouldn't have any errors now
     $this->assertTrue($this->redis->getLastError() === NULL);
     // Throw some invalid lua at redis
     $this->redis->eval("not-a-lua-script");
     // Now we should have an error
     $evalError = $this->redis->getLastError();
     $this->assertTrue(strlen($evalError) > 0);
     // test getLastError with a regular command
     $this->redis->set('x', 'a');
     $this->assertFalse($this->redis->incr('x'));
     $incrError = $this->redis->getLastError();
     $this->assertTrue($incrError !== $evalError);
     // error has changed
     $this->assertTrue(strlen($incrError) > 0);
     // clear error
     $this->redis->clearLastError();
     $this->assertTrue($this->redis->getLastError() === NULL);
 }
开发者ID:stonegithubs,项目名称:phpredis,代码行数:20,代码来源:TestRedis.php

示例14: 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

示例15: 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


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