Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Lock] Better key naming when possible#60526
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Conversation
Use plain text for key name when they are short enough.It helps to understand where inserted locks come from when looking at the database.
I'm not sure how to test this change, any feedback/tips are welcome! |
@@ -48,8 +48,12 @@ private function init(array $options, float $gcProbability, int $initialTtl): vo | |||
/** | |||
* Returns a hashed version of the key. |
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.
Needs to be adjusted
This creates collisions for keys, as a long key is not considered the same resource than its hash. |
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.
I'm not sure I see what you mean@stof, can you please expand a bit?
Is there a reasonable case where the key could contain something binary? Shouldn't we hash it when it happens?
private functiongetKeyName(Key $key): string | ||
{ | ||
$keyAsString = (string) $key; | ||
if (strlen($keyAsString) <= 64) { | ||
return $keyAsString; | ||
} | ||
return hash('sha256', (string) $key); |
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.
It'd keep the original name + leverage PHP to do the cast:
privatefunction getKeyName(Key$key):string | |
{ | |
$keyAsString = (string)$key; | |
if (strlen($keyAsString) <=64) { | |
return$keyAsString; | |
} | |
returnhash('sha256', (string)$key); | |
privatefunction getHashedKey(string$key):string | |
{ | |
returnstrlen($keyAsString) <=64 ?$key :hash('sha256',$key); |
Uh oh!
There was an error while loading.Please reload this page.
Use plain text for key names when they are short enough.
It helps to understand where inserted locks come from when looking at the database.
See#57906 for examples of how the locks look like in the database.