-
Notifications
You must be signed in to change notification settings - Fork 139
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
fix: add disconnect
to memcache driver
#865
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #865 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2590 2594 +4
Branches 339 339
=========================================
+ Hits 2590 2594 +4
☔ View full report in Codecov by Sentry. |
Hi @Julien-R44 👋 - Thanks so much for sending the pull request. If you could add in the unit tests for this change then we could get this merged. |
Added a test for this one. If this is by design, we should absolutely fix it on the keyv side. Look at this code : const memcached = new KeyvMemcache('localhost:11211')
const memcache = new Keyv({ store: memcached })
try {
console.log('go')
await memcache.get('foo')
await memcache.disconnect()
await memcached.get('foo')
console.log('done 1')
} catch (err) {
console.log('done 2')
}
console.log('done 3') Guess the output 😄
output will not include Because this promise : https://github.com/JuliensForks/keyv/blob/main/packages/memcache/src/index.ts#L48 is never resolving. ( This will only be the case after this PR has been applied. Because right now, the |
@@ -163,6 +163,10 @@ class KeyvMemcache<Value = any> extends EventEmitter implements Store<Value> { | |||
}); | |||
}); | |||
} | |||
|
|||
async disconnect(): Promise<void> { | |||
this.client.quit(); |
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.
to force the quit you might want to do close()
as that might resolve the issue you are seeing
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.
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.
ok. thanks for trying. Should we wait to see what memjs says?
that is interesting. Did you want to provide a fix for this in the library as i would like to not add it if it does nothing at this time. you could also look at close which might do the trick. |
Not sure I understand what you're proposing
For this, we have two solutions:
let me know what you think is best and i'll do a PR |
If you want to do the fix we can support that. If not, lets wait a week to see what they say. |
@Julien-R44 looks like there was a comment. memcachier/memjs#172 (comment) Thoughts on that? |
Yeah, I'll try to send a PR to memjs and then update our PR accordingly once the problem has been fixed |
Any word on the PR for memjs? Anything I can do to help? |
hey! i am sorry to leaving this hanging. i started looking but it's a bit complicated. it's very oldschool js code and a bit low level. |
sorry, I decided to not add memcached support to my application after all. So unfortunately I won't be able to complete this PR. I'll let you decide whether to close it or not |
@Julien-R44 - thanks for the update and we will look to see if we want to continue on this PR. |
closing and will look at this later |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Without this change, this code was never exiting :
So just added a
disconnect
method to the memcache driver, and now works fineWanted to add a test for the same :
but it doesn't work. memjs throws 0 errors when you do a
.get
or.set
when the connection is closed. So not sure how to handle this