當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Redis::decr方法代碼示例

本文整理匯總了PHP中Redis::decr方法的典型用法代碼示例。如果您正苦於以下問題:PHP Redis::decr方法的具體用法?PHP Redis::decr怎麽用?PHP Redis::decr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Redis的用法示例。


在下文中一共展示了Redis::decr方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDecr

 public function testDecr()
 {
     $this->redis->set('key', 5);
     $this->redis->decr('key');
     $this->assertEquals(4, $this->redis->get('key'));
     $this->redis->decr('key');
     $this->assertEquals(3, $this->redis->get('key'));
     $this->redis->decr('key', 2);
     $this->assertEquals(1, $this->redis->get('key'));
 }
開發者ID:hieutrieu,項目名稱:phpredis,代碼行數:10,代碼來源:TestRedis.php

示例2: decrement

 /**
  * Decreases the value
  *
  * @param   string $key
  * @param   int $value
  * @return  void
  */
 public function decrement($key, $value = 1)
 {
     if ($value == 1) {
         $this->_redis->decr($this->_prefix . $key);
     } else {
         $this->_redis->decrBy($this->_prefix . $key, $value);
     }
 }
開發者ID:melihucar,項目名稱:lime-cache,代碼行數:15,代碼來源:RedisDriver.php

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

示例4: testDecr

 public function testDecr()
 {
     $this->redis->set('key', 5);
     $this->redis->decr('key');
     $this->assertEquals(4, (int) $this->redis->get('key'));
     $this->redis->decr('key');
     $this->assertEquals(3, (int) $this->redis->get('key'));
     $this->redis->decr('key', 2);
     $this->assertEquals(1, (int) $this->redis->get('key'));
     $this->redis->decr('key', 2);
     $this->assertEquals(-1, (int) $this->redis->get('key'));
     $this->redis->decrBy('key', 2);
     $this->assertEquals(-3, (int) $this->redis->get('key'));
     $this->redis->decrBy('key', 1);
     $this->assertEquals(-4, (int) $this->redis->get('key'));
     $this->redis->decr('key', -10);
     $this->assertEquals(6, (int) $this->redis->get('key'));
 }
開發者ID:0,項目名稱:phpredis,代碼行數:18,代碼來源:TestRedis.php

示例5: decrement

 /**
  * Decrement a raw value
  *
  * @param	string	$id	Cache ID
  * @param	int	$offset	Step/value to reduce by
  * @return	mixed	New value on success or FALSE on failure
  */
 public function decrement($id, $offset = 1)
 {
     return $this->_redis->decr($id, $offset);
 }
開發者ID:dhamodhar,項目名稱:mysmartportal,代碼行數:11,代碼來源:Cache_redis.php

示例6: getUserList

        // 還存在商品,將用戶放入一個數組中
        // 判斷用戶是否已經搶過了
        $exist = 0;
        $userArr = getUserList();
        foreach ($userArr as $key => $user) {
            if ($userArr[$key]['ip'] == $ip) {
                $exist = 1;
                break;
            }
        }
        if ($exist) {
            $arr['msg'] = $ip . '您已經搶到了商品,不能重複搶哦!';
        } else {
            $userInfo = array('ip' => $ip, 'addtime' => microtime());
            $redis->rPush('userlist', json_encode($userInfo));
            $redis->decr('goods_count');
            $arr['succ'] = 'T';
            $arr['msg'] = $userInfo['ip'] . '恭喜您,搶到了商品!';
        }
    } else {
        // 不存在商品了,直接返回數據
        $arr['msg'] = '商品已經搶光了,謝謝您的參與,下次再來吧';
    }
    backjson($arr);
} elseif ($act == 'user') {
    //獲取中獎用戶
    $msg = "";
    $userArr = getUserList();
    if (!empty($userArr)) {
        foreach ($userArr as $user) {
            $msg .= "<tr>\r\n            <td>" . $user['ip'] . "</td>\r\n            <td>" . $user['addtime'] . "</td>\r\n        </tr>";
開發者ID:sunlyliuh,項目名稱:myproject,代碼行數:31,代碼來源:miaosha.php

示例7: decrement

 /**
  * Decrement a raw value
  *
  * @param    string $id Cache ID
  * @param    int $offset Step/value to reduce by
  * @return    mixed    New value on success or FALSE on failure
  */
 public function decrement($id, $offset = 1)
 {
     return $this->_redis->exists($id) ? $this->_redis->decr($id, $offset) : FALSE;
 }
開發者ID:at15,項目名稱:codeignitordb,代碼行數:11,代碼來源:Cache_redis.php

示例8: decr

 /**
  * @param string $key
  * @return int
  */
 public function decr($key)
 {
     try {
         $this->_useCnt++;
         return parent::decr($key);
     } catch (Exception $e) {
         Wk::logger()->err($e->getMessage());
     }
     return 0;
 }
開發者ID:telander,項目名稱:waka,代碼行數:14,代碼來源:Wk_Redis.php

示例9:

$redis->setnx('key', 'value');
$redis->set('key1', 'val1');
$redis->set('key2', 'val2');
$redis->set('key3', 'val3');
$redis->set('key4', 'val4');
$redis->delete('key1', 'key2');
/* return 2 */
$redis->delete(array('key3', 'key4'));
/* return 2 */
$redis->set('key', 'value');
$redis->exists('NonExistingKey');
$redis->incr('key1');
/* 4 */
$redis->incrBy('key1', 10);
/* 14 */
$redis->decr('key1');
/* -2 */
$redis->decr('key1');
/* -3 */
$redis->decrBy('key1', 10);
/* -13 */
$redis->mGet(array('key1', 'key2', 'key3'));
$redis->mGet(array('key0', 'key1', 'key5'));
$redis->set('x', '42');
$exValue = $redis->getSet('x', 'lol');
// return '42', replaces x by 'lol'
$newValue = $redis->get('x');
// return 'lol'
$redis->select(0);
// switch to DB 0
$redis->set('x', '42');
開發者ID:isS,項目名稱:NoSQL,代碼行數:31,代碼來源:phpRedis.php

示例10: decrement

 /**
  * Enter description here...
  *
  * @param string $p_sKey The Key
  * @param numeric $p_iDec The decremental value
  * @return numeric
  */
 function decrement($p_sKey, $p_iDec = 1)
 {
     return $this->_handler->decr($p_sKey, $p_iDec);
 }
開發者ID:revolveweb,項目名稱:ppi-framework,代碼行數:11,代碼來源:Redis.php

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

示例12: array

    描述:數字遞減存儲鍵值。
    參數:key value:將被添加到鍵的值
    返回值:INT the new value
    incr
    描述:數字遞減存儲鍵值。
    參數:key value:將被添加到鍵的值
    返回值:INT the new value
*/
$redis->set('test', "100");
var_dump($redis->incr("test")) . '<br>';
//結果:int(101)
var_dump($redis->incr("test")) . '<br>';
//結果:int(102)
$redis->set('test1', "10");
var_dump($redis->decr("test1")) . '<br>';
//結果:int(9)
var_dump($redis->decr("test1")) . '<br>';
//結果:int(8)
/**
  getMultiple

  描述:取得所有指定鍵的值。如果一個或多個鍵不存在,該數組中該鍵的值為假
  參數:其中包含鍵值的列表數組
  返回值:返回包含所有鍵的值的數組
*/
$arr = array('136502993', 'zhuwawa');
$int = 100;
$string = 'my love....';
$redis->set('demo2', $arr);
$redis->set('demo3', $int);
開發者ID:wujunze,項目名稱:bigpan,代碼行數:30,代碼來源:redis.php


注:本文中的Redis::decr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。