Redis SCARD返回错误的结果?

时间:2015-06-29 16:44:01

标签: php redis predis

我将大量数据点添加到redis集中:

$t = 0;
$redis = Redis::Connection();
foreach($adv as $a) {
    $t = $t + 1;
    print($t); //Prints to log

    $test = $redis -> sadd('database/ab/AL', $a -> id);
    print($test); //Prints to log
}

当我致电redis->scard('database/ab/AL')时,我得到了结果9832,我应该得到的答案是9866

$t是我用来检查循环正在进行多少次迭代的计数器,并且$t在运行循环之后是9866,这很奇怪,考虑到scard正在返回{{ 1}}

然后我想可能会添加重复内容,所以我记录了来自9832的回复

sadd

整个日志中没有零,这意味着要添加的每个元素都是唯一的。还有1 [2015-06-29 16:24:55] local.INFO: 1 [] [] 2 [2015-06-29 16:24:55] local.INFO: 1 [] [] 3 [2015-06-29 16:24:55] local.INFO: 1 [] [] 4 [2015-06-29 16:24:55] local.INFO: 1 [] [] 5 [2015-06-29 16:24:55] local.INFO: 1 [] [] 6 [2015-06-29 16:24:55] local.INFO: 1 [] [] ... 9861 [2015-06-29 16:24:59] local.INFO: 1 [] [] 9862 [2015-06-29 16:24:59] local.INFO: 1 [] [] 9863 [2015-06-29 16:24:59] local.INFO: 1 [] [] 9864 [2015-06-29 16:24:59] local.INFO: 1 [] [] 9865 [2015-06-29 16:24:59] local.INFO: 1 [] [] 9866 [2015-06-29 16:24:59] local.INFO: 1 [] [] 个日志调用与9866结果相矛盾。 我试过用redis-cli检查,但我仍然得到错误的结果。 是什么给了什么?

1 个答案:

答案 0 :(得分:2)

我实际上是用变量键入值:

$redis->sadd('database/ab/state:'.$a->state, a->id);

结果显示某些状态为小写,将这些值发送到另一个键。

修复:$redis->sadd('database/ab/state:'.strtoupper($a->state), a->id);

现在,当我致电9866

时,我会收到正确的号码SCARD

请务必仔细检查您的密钥名称!