-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Redis cache store issues on numeric values #31345
Comments
Managed to reproduce this. Sending in a fix. Also not really sure about other stores. |
Should the complete fix be for the next major release, as considering returning 1 instead of "1" be a possible breaking change? |
Came across this today when we tried switching to redis. Some of the stuff in our cache is type sensitive, so when some of the cache keys went from It seems this is sort of broken for all numeric strings, since |
@carestad I agree. These are some reasons for the inconsistency, although I don't think they are good enough:
I suggest to update Redis driver to only skip serialization if the data type is int, but not when the data is float or a numeric string. This change probably is a breaking change for some other applications. |
@halaei Tough one. It all boils down to the fact that redis don't have its own numerical type I suppose. But I was not really aware of this before trying it out. I feel like this should be mentioned in the documentation somewhere, that integers and float types will not be preserved when using redis? Especially since all the other cache providers does this (haven't tried dynamodb and apc yet though so I can't say 100% for that one, but I have tested What about a |
Just got burned by this as we switched our cache store from database to redis - suddenly this throws an error on the second call: function foo(): int
{
return Cache::remember('foo', 60, function() {
return 1;
});
} => Is there any fix other than manually casting to int everywhere that's the expected type? The fix that closes this issue (#31348) deals with storing |
you can use PHP’s serialize/unserialize to store type info |
@lptn Thanks for your reply. If I understand it correctly, this would look something like I could write a custom driver extending the RedisStore to not skip the integer serialization they are doing here: framework/src/Illuminate/Cache/RedisStore.php Lines 332 to 335 in 6718ae6
But that would have an impact on the |
Can this be reopened? This inconsistency bug is still present in laravel 8 |
Running into this whilst profiling/memory tuning redis, if this is fixed, it would provide a big memory saving:
|
Why this is closed when it's not fixed or resolved anyhow? @taylorotwell your PR closed this, not sure if this was mistake or what. |
Description:
RedisStore::serialize()
andunserialize()
don't do right when it comes to caching numbers. I think the code has some considerations that Redis stores strings that are integers more efficient than normal integers. But the implementation is wrong.From https://redis.io/commands/INCR:
Steps To Reproduce:
Set cache driver to redis and try the followings:
I don't know if other drivers have similar issues.
The text was updated successfully, but these errors were encountered: