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,有些蒙
怪我咯2017-04-24 09:12:30
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