vendredi 20 mai 2016

Issue converting bitset_to_string to BitSet class from (v1.0.1 to v2.0.3)

I am having an issue when replacing the bitset_to_string function with the BitSet class (bitset 2.0.3). My test code:

<?php
$redis = get_redis();
$key = "pageviews:homepage:latest";

$redis->del($key);
$redis->setbit($key, 1, 1);
$redis->setbit($key, 3, 1);
$redis->setbit($key, 5, 1);
$redis->setbit($key, 8, 1);
$redis->setbit($key, 9, 1);
$redis->setbit($key, 10, 1);
$redis->setbit($key, 15, 1);
$redis->setbit($key, 150, 1); // issue

$bitset = $redis->get($key);

// $ redis-cli GET pageviews:homepage:latest
// "T\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"

$data = false;
if (class_exists('BitSet')) {
    $bs = new BitSet();
    $b = $bs->fromRawValue($bitset);
    $data = $b->__toString();

    // Output
    // 00101010100001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

} else {

    $data = bitset_to_string($bitset);

    // Output:
    // 00101010100001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000
}

var_dump($data);
exit;

As you can see from the code, the bitset_to_string function is working correctly returning all set bits but the BitSet class omits the bit set at offset 150.

Is my usage of BitSet class correct or not? If not, how should I replace the bitset_to_string function with the class?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire