phpredis - Redis中incr的問題
阿神
阿神 2017-04-24 09:10:30
0
3
736

Redis版本

我後台的程式設定了會員ID的起始數

<?php
$redis->set('userId',intval($start));
?>

前台的會員註冊會取得這個userId,然後當做它的ID

<?php
$userId = $redis->get('userId');
if($model->insert(['userId'=>$userId])){
    $redis->incr('userId');
}

但現在的問題是,我無論怎麼註冊會員,這個redis中的userId都不會變,在伺服器上操作

incr userId

會回傳錯誤「(error) ERR value is not an integer or out of range」

get userId
"i:10003;"

求大神,沒用過幾次redis,有些蒙

阿神
阿神

闭关修行中......

全部回覆(3)
刘奇

我猜想你初始化程式碼的時候用了

$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);

所以到資料庫的最終值是一個字串 "i:10003;",而字串就不能 incr 了

$r = $redis->incr('userId'); // 这里的返回值应该是 false

如果你一定要使用序列化,只能將就使用 zIncrBy,zIncrBy 被序列化的是 member,操作的是 score,所以不會受到影響

洪涛

我這個是可以的,你按照我的試試。

PHPzhong

"i:10003;"設定的userId根本不是數字啊

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板