php - Redis SCARD returning the wrong results? -


i'm adding large number of data points redis set:

$t = 0; $redis = redis::connection(); foreach($adv $a) {     $t = $t + 1;     print($t); //prints log      $test = $redis -> sadd('database/ab/al', $a -> id);     print($test); //prints log } 

when call redis->scard('database/ab/al') result 9832, answer should getting 9866

$t counter put in check how many iterations loop doing, , $t 9866 after running loop, weird considering scard returning 9832

then thought maybe there duplicates being added, logged response 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 [] [] 

there no zeros in entire log, means each element being added unique. there 9866 log calls contradicts scard result. have tried checking redis-cli , still wrong results. gives?

i keying values variable:

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

turns out states in lowercase, sent values key.

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

now correct number, 9866, when call scard

always double check key names!


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -