Answer the question
In order to leave comments, you need to log in
How to properly extract data from bitmap-a redis?
Let's say there is a final key in redis from 0\1 (bitmap).
1 - the product met the condition, 0 - not.
Position 0\1 means product id.
50000 items.
How to correctly extract the positions of goods that fit the conditions?
$ar = [];
for($i = 0; $i < 50000; $i++){
if ($redis->getBit('test', $i) == 1){
$ar[] = $i;
}
}
Answer the question
In order to leave comments, you need to log in
for ($i = 0; $i < $len; $i++){
$tmp = ord($string[$i]);
for($j=0; $j<8; $j++){
$result[] = (($tmp & (1 << $j)) != 0);
}
}
50000 roundtrips to the radish from php for each page request is strong )
just take the entire 'test' key from the radish once, and then bit arithmetic will help you.
$redisProducts = $redis->get('test');
$ar = [];
for($i = 0; $i < 50000; $i++){
if ($redisProducts & pow(2, $i)){
$ar[] = $i;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question