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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃挩 Expose Get keys from RedisCache #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

馃挩 Expose Get keys from RedisCache #84

wants to merge 3 commits into from

Conversation

ElicNg
Copy link

@ElicNg ElicNg commented Feb 6, 2024

Problem

Having access to the list of keys is important in cases where we want to manipulate the cache such as deletes based on a pattern.

Solution

Exposing keys function from Redis allow us to find keys matching a certain pattern, thus allowing the dev to seek and delete expected caches.

Potential issue

Get Keys is O(n), n is the number of keys in cache and locks the instance while looping through all items. A potential solution is to use SCAN instead. But in this case, it will only be used in connectors which won't have a lot of cached items.

@ElicNg
Copy link
Author

ElicNg commented Feb 6, 2024

P.S. I removed some internal informations from the description. If you need more information, please ping me.

* a value fetching. We don't want to hang forever if this is the case.
*/
this.emit('warn', 'Error while fetching keys from the Redis cache', error);
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this an issue for the client? If an empty array is returned, how can we know if it's because there is no keys matching the pattern or if there are keys matching the patterns but we failed to return them?

Copy link
Contributor

@ronjouch ronjouch Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to gr芒g's comment. What about changing this from returning a Promise<string[]> to returning a Promise<{ status: 'success' | 'timeout' | 'other-error', result: string[] }> ? That will let the client handle the timeout.

@@ -27,6 +26,17 @@ export abstract class CacheInstance extends EventEmitter {
*/
public abstract getValue(key: string): Promise<CachableValue>;

/**
* Find all keys matching the given pattern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the O(n)-ness!

Suggested change
* Find all keys matching the given pattern
* Find all keys matching the given pattern.
*
* PERFORMANCE WARNING: this is O(keys) / will TRAVERSE ALL KEYS!
* Both our Local & Redis implems can traverse a lot of keys quickly,
* but be extremely careful calling this! This should be used for
* occasional operations, not for high-frequency calls!

/**
* @inheritdoc
*
* Only support wildcard (*) globstyle pattern. Use RedisCache for more advanced pattern matching.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Only support wildcard (*) globstyle pattern. Use RedisCache for more advanced pattern matching.
* Only supports wildcard (*) globstyle pattern. Use RedisCache for more advanced pattern matching.

* a value fetching. We don't want to hang forever if this is the case.
*/
this.emit('warn', 'Error while fetching keys from the Redis cache', error);
return [];
Copy link
Contributor

@ronjouch ronjouch Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to gr芒g's comment. What about changing this from returning a Promise<string[]> to returning a Promise<{ status: 'success' | 'timeout' | 'other-error', result: string[] }> ? That will let the client handle the timeout.

@ianfdk ianfdk removed their request for review February 7, 2024 16:12
@AdelUnito AdelUnito removed their request for review February 13, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants