-
-
Notifications
You must be signed in to change notification settings - Fork 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
Modify cache redis backend #11608
Modify cache redis backend #11608
Conversation
# Changes 1. Modify cache redis backend, delete _PHCR 2. Cache redis backend supports "client" option, now you can pass a redis client # Why 1. The redis cache backend use a special key _PHCR to store all keys used by cache. There is a issue: phalcon#10905 .According to @Green-Cat ,it is disabled in 2.0.x branch which is not true. If use _PHCR, every time we set a cache, we have to run sAdd and set commands. Store all keys in _PHCR will cause it expands quickly and this will influence performance. 2. The previous implementation mixes statsKey and prefix, it uses _PHCR as super prefix which is not needed. 3. The cache backend doesn't support redis option which means that we can not pass a redis connection. So if we use modelsCache and modelsMetadata, there will be two redis connections. So I modify this part and let redis option be supported, and through the lifetime of a request we can use one redis connection.
See #11452 |
I'll look into this as soon as I can |
@@ -88,13 +99,21 @@ class Redis extends Backend implements BackendInterface | |||
} | |||
|
|||
if !isset options["statsKey"] { | |||
// Disable tracking of cached keys per default | |||
let options["statsKey"] = ""; | |||
let options["statsKey"] = "_PHCR"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modify cache redis backend, delete _PHCR
As I remember it was done in pantaovay@6b88422
Why are we again added _PHCR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is inconsistent with the document. But current implementation is inconsistent with other cache backends😭. I will modify the document instead.
Is that PR still being worked on? |
Hi, just to let you know, this _PHCR is a pain for us, it eats all the memory from our Redis: the keys are stored with TTL, so after they expire, redis removes it, but _PHCR keeps growing regardless if the keys exist or not (there is no explicit key removal from php, we rely on TTL). Why not to modify all cache backends that they'd interpret null value as not to use the stats key? |
Sorry for using a language that is not related to the project, but this what we have to run from time to time to clean up that key without affecting the production, maybe it might be useful for someone else:
|
Just to let you know, the _PHCR prefix really is annoying. We for instance use the redis cache across multiple applications. Phalcon in our case created the redis cache data since it acts as a receiver of measurement data. In Phalcon 1.x with the incubator package we did not have the prefix behavior and so all the cached data in Redis is not prefixed. However since we can't stay legacy we are forced to upgrade resulting in upgrading our whole application stack to support the prefix... It would really help us if there would come a solution in which the key is optional. |
Will this be added to 3.3.3? Really Looking forward to it 😁 |
Closing in favor of #13563 |
* niden-feature/T11608-modify-redis-backend: (28 commits) [#11608] - Removed unused variables [#11608] - Reverting instantiation of the client [#11608] - Removed '_' from variables and methods [#11608] - Refactoring on the connect to check if the object is already initialized/connected [#11608] - Refactoring of the getClient() [#11608] - Fixed tabs [#11608] - Corrections based on review [#11608] - Corrected variable name [#11608] - Corrected costructor and changelog [#11608] - Updated the changelog [#11608] - Corrected tests [#11608] - Fixed typos [#11608] - More corrections [#11608] - Modifications to the class; Adjusted tests [#11608] - Changed the comparison for the key on save [#11608] - More corrections [#11608] - Changed the instatiation of redis [#11608] - Trying protected getClient [#11608] - Changed the getClient slightly [#11608] - Corrections to variables ...
Changes
set
method supportsttl
,the call ofsettimeout
is removedexists
method to check if a key exists, the previous implementation usesget
which is wrongWhy
_PHCR
will cause it expands quickly and this will influence performance.statsKey
andprefix
, it uses_PHCR
as super prefix which is not needed.