matthiasmullie / scrapbook

PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
https://www.scrapbook.cash
MIT License
315 stars 27 forks source link

Redis wrong default value #46

Closed nsn0x01 closed 1 year ago

nsn0x01 commented 4 years ago

I'm using Redis adapter with SimpleCache implementation and I guess there is a bug here.

$testStore = new SimpleCache(new Redis($client)); var_dump($testStore->get('missedKey'));

For the key missed I'm expecting the $default value defined by this method.

` public function get($key, $default = null) { $this->assertValidKey($key);

    // KeyValueStore::get returns false for cache misses (which could also
    // be confused for a `false` value), so we'll check existence with getMulti
    $multi = $this->store->getMulti(array($key));

    return isset($multi[$key]) ? $multi[$key] : $default;
}

`

The result for the key missed is instead the boolean "false" when the default is "null".

matthiasmullie commented 1 year ago

This was fixed with 31f45780a2f1a28cb3f928c631f311dcb0912c96