本文整理匯總了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'));
}
示例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);
}
}
示例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));
}
示例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'));
}
示例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);
}
示例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>";
示例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;
}
示例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;
}
示例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');
示例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);
}
示例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;
}
示例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);