-
Notifications
You must be signed in to change notification settings - Fork 0
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
Client insights #11
Comments
Yep, makes sense. I've done similar in some of my projects.
Good question. I have mainly used the HashPool where I've implemented a polling check https://github.com/joshbetz/node-memcached/blob/main/src/hashpool.ts#L57-L61
This is an interesting idea. Do you have examples? |
Great, thx for the feedback!
Understood. But even leveraging the polling check feature (which I recommend to add in the README ❤️) I believe consumers will still be in trouble. import { Pool } from '@joshbetz/memcached' ;
const memcached = new Pool( 11211, 'localhost' );
const key = 'key';
const cached = await memcached.get(key);
if (cached) { // <-- If cached === false we don't really know if it is a cache miss or a connection issue
...
}
await memcached.set(key, 'value'); // <-- So at this point, does it really makes sense to "set"? Maybe there was a connection issue Even in the following scenario: import { Pool } from '@joshbetz/memcached' ;
const memcached = new Pool( 11211, 'localhost' );
const key = 'key';
let cached: string;
// Between A and B we can still have connection issues
const ready = await memcached.ready(); // <-- A
if (ready) {
cached = await memcached.get(key); // <-- B
} else {
throw new Error('Connection issue')
}
if (cached) { // At this point we still don't know if there was a cache miss or a connection issue
...
}
await memcached.set(key, 'value'); Please correct me if I'm missing something. Would it be an option to return
Sure! Node.js provides the
This is the util. Side note: I believe |
Can you tell me more about the use case? What would you do differently if you knew it was a connection failure at the time of the query as opposed to polling for the connection status?
IMO this is outside the scope of the library for now. |
Hi Josh! And thank you in advance for your consideration.
Let's assume that interacting with Memcached is part of an HTTP request/response flow. If data cached:
otherwise
I believe during traffic spikes cache, even if super fast, will be under pressure.
More generally, I think that if it is not possible to interact with Memcached for any reason, the code should break or raise some kind of exception. Let me know your thoughts. It is also possible that I'm missing something from your client and what I'm describing is already possible tweaking it. I'm also interested to eventually listen how would you leverage
Side note: in |
So you want to avoid the |
I would like to understand if I would do the same also in case of E.g if connection is ok and you try to cache something really big without knowing caching value limits, returning just false is a lil bit weak for the consumer.
import { Pool } from "@joshbetz/memcached";
const memcached = new Pool(11211, "localhost", { forwardPoolErrors: true });
const cached = await memcached.get("key");
if (!cached) {
console.log("Not cached");
const setResult = await memcached.set("key", "my-value");
console.log("Set result: ", setResult);
} else {
console.log("Cached: ", cached);
}
process.exit(0); In version
Why did you removed it? I think throw expressive exceptions is the way to go. |
You can still listen for the error event https://github.com/joshbetz/node-memcached/blob/main/src/pool.ts#L48 |
Thank you, that's great! To keep it simple, I might implement something like this: import { Pool } from "@joshbetz/memcached";
class MyMemcachedWrapper {
constructor(private readonly client: Pool) {
this.client.on("error", (error) => this.throwOnError(error));
}
throwOnError(error: Error) {
throw new Error(`The following error occurred: ${error.message}`);
}
myWrappedGet(key: string) {
return this.client.get(key);
}
}
try {
const client = new Pool(11211, "localhost");
const myMemcachedWrapper = new MyMemcachedWrapper(client);
const cached = await myMemcachedWrapper.myWrappedGet("myKey");
console.log(cached);
process.exit(0);
} catch (e) {
console.error(e);
process.exit(1);
} |
Hello Josh!
I wanted to reach out and first express my gratitude for your Memcached client implementation. After extensively testing various Memcached clients in the JavaScript ecosystem, I've found yours to be the most compelling solution for several reasons:
I previously attempted to contact you through other channels without success. While I was hesitant to open an issue just to start a conversation, seeing your recent active contributions encouraged me to reach out this way.
I'm currently developing a Memcached wrapper for the NestJS backend framework. As I'm working on version 4, I'd like to switch to your client implementation (
Pool
). However, I've encountered some questions and concerns that I'd really appreciate your insights on:.set()
and.get()
operations return boolean values without throwing exceptions. While this helps identify cache misses and successful operations, it makes it challenging to distinguish connection issues from other failures. The only solution I've found is running .ping() before operations, though this doesn't guarantee connection stability during execution. Do you have any recommendations for more robust error handling?I would be incredibly grateful for any opportunity to discuss these points with you. If you'd prefer to continue this conversation through other channels, you can find all my contact information on my public GitHub profile. Your insights would be invaluable in helping shape the development of my wrapper.
Looking forward to hearing your thoughts!
The text was updated successfully, but these errors were encountered: