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