Giter VIP home page Giter VIP logo

Comments (5)

mmkal avatar mmkal commented on September 10, 2024

Hmm I'm not sure I understand the use-case. Do you have a code example of how you'd like to handle this situation if the library supported it?

from handy-redis.

ssut avatar ssut commented on September 10, 2024

It would be like:

const blockingClient = client.duplicate();

instead of createHandyClient(await client.duplicate()). Thanks.

from handy-redis.

mmkal avatar mmkal commented on September 10, 2024

Do you know if client.duplicate() is always synchronous? I'm wary to put this in, in case that's not always the case. I haven't used it myself, and I assume it's an async call in node_redis for a reason.

In the meantime, if it's definitely safe in your case, could you avoid the await (which I can see is annoying if you want to create a client in a non-async context) by doing

const blockingClient = createHandyClient(client.duplicate() as any);

?

from handy-redis.

ssut avatar ssut commented on September 10, 2024

I didn't know if that workaround would work because client.duplicate() with handy-redis returns a Promise. Well, then I suggest you make a high-level API that could be a shortcut of createHandyRedis(client.duplicate()), like client.duplicateAsyncClient() or something.

from handy-redis.

mmkal avatar mmkal commented on September 10, 2024

You're right - it would be a promise. I would still rather not add this to the API, I'd like to avoid special cases where possible. This is working for me though:

it("can use duplicate", async () => {
    const first = createHandyClient();
    const second = createHandyClient(first.redis.duplicate());

    await first.set("one", "hello");
    await second.set("two", "goodbye");

    expect(await first.get("two")).toEqual("goodbye");
    expect(await second.get("one")).toEqual("hello");
});

This should be good enough, unless I can find a better way to handle synchronous node_redis methods.

from handy-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.