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

Function returning a promise #18

Open
kennedyrs opened this issue Jan 31, 2020 · 2 comments
Open

Function returning a promise #18

kennedyrs opened this issue Jan 31, 2020 · 2 comments

Comments

@kennedyrs
Copy link

When using Redis, the function below returns a promise to the count variable

count() {
        let count = this.store.get(this.key)
        if (typeof count === 'undefined') {
            return 0
        }
        return count
    }
@AndrewJo
Copy link
Contributor

AndrewJo commented Feb 4, 2020

Hey @kennedyrs, thanks for reporting the bug. Redis driver uses promises because network I/O to Redis shouldn't block the Node.js event loop. This is not a problem for Memory driver since we can directly access the memory synchronously without blocking the event loop.

In fact, any driver written for external caches such as Redis, Memcached, etc. will have to be promises.

@masasron is it alright if I promisify all of the this.store methods? Memory driver will just resolve the promise right away (e.g. wrapped in Promise.resolve()) but it should make accessing the store much more consistent.

@masasron
Copy link
Owner

masasron commented Feb 6, 2020

@AndrewJo yes I think that would be a good idea, but since this is a breaking change for the memory driver we need to release this as a minor release.

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

No branches or pull requests

3 participants