phpredis - Redis中incr的问题
阿神
阿神 2017-04-24 09:10:30
0
3
739

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,有些蒙

阿神
阿神

闭关修行中......

reply all(3)
刘奇

I guess you used it when initializing the code

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

So the final value to the database is a string "i:10003;", and the string cannot be incr

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

If you must use serialization, you can only use zIncrBy. What is serialized by zIncrBy is member and the operation is score, so it will not be affected

洪涛

This is okay for me, you can try it according to my instructions.

PHPzhong

"i:10003;"The userId set is not a number at all

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template