Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Laravel cache does not support false as a cached value anymore #17188

Closed
halaei opened this issue Jan 7, 2017 · 11 comments
Closed

[5.4] Laravel cache does not support false as a cached value anymore #17188

halaei opened this issue Jan 7, 2017 · 11 comments
Labels

Comments

@halaei
Copy link
Contributor

halaei commented Jan 7, 2017

  • Laravel Version: 5.4

Description:

I think #15160 has an unnecessary change that should be undone, unless there is a reason for that:

Illuminate/Cache/RedisStore and Illuminate/Cache/Repository now check key existence using null or false.

In the code, all the checks for if (is_null($value)) are converted to if (is_null($value) || $value === false). IMHO, it adds an unnecessary limitation to the Laravel Cache.

@tillkruss do you agree?

Steps To Reproduce:

\Cache::put('x', false, 60);
var_dump(\Cache::has('x'));

Expected output:

true

Actual output:

false

@tillkruss
Copy link
Contributor

tillkruss commented Jan 7, 2017

Predis returns null when a cache key doesn't exists. PhpRedis and HHVM usually return false. Since 5.4 now fully supports PhpRedis you'ldo need to use something like "false" or 0 or "no" from 5.4 onwards.

@GrahamCampbell
Copy link
Member

To get around this, we could get each connector to throw an exception for a miss?

@halaei
Copy link
Contributor Author

halaei commented Jan 7, 2017

@tillkruss
I think laravel is not supposed to support HHVM anymore? I have no idea about returning false instead of null by PhpRedis. If it is true, then maybe the redis driver should handle false itself. Moreove, maybe Redis Queue driver needs fixes for that as well?

    public function get($key)
    {
        $value = $this->connection()->get($this->prefix.$key);
        if (! is_null($value) && $value !== false) {
            return $this->unserialize($value);
        }
    }

@GrahamCampbell
Copy link
Member

Indeed, HHVM support has been dropped.

@taylorotwell
Copy link
Member

It's probably indeed true we need a PR to normalize this across the drivers so that null is returned for miss from both.

@tillkruss
Copy link
Contributor

tillkruss commented Jan 7, 2017

I don't think storing PHP types like booleans in Redis is a good idea in general.

  • true is stored as 1
  • false is stored as an empty string

For both, Predis and PhpRedis.

However the root problem seems to be that Illuminate\Cache\Repository::has() is using a GET call to check that a keys exists and it should really be using an EXISTS call. That would solve the problem no matter what client is used and what values users store.

@halaei
Copy link
Contributor Author

halaei commented Jan 7, 2017 via email

@tillkruss
Copy link
Contributor

Right, when using Laravel's cache, not when using Redis directly.

@tillkruss
Copy link
Contributor

See #17196 (comment)

@casperbakker
Copy link

It's probably indeed true we need a PR to normalize this across the drivers so that null is returned for miss from both.

That's it. I am done with Laravel. What is this for a reason? Cache::has() should only check if the key exists and nothing more. Why even check the inner results?

@laravel laravel locked and limited conversation to collaborators Sep 19, 2017
@tillkruss
Copy link
Contributor

tillkruss commented Sep 19, 2017

@casperbakker: Feel free to open a discussion on https://github.com/laravel/internals about this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants