当前位置: 首页>>代码示例>>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;未经允许,请勿转载。