Git Product home page Git Product logo

Comments (18)

andylash avatar andylash commented on June 2, 2024 2

here's a PR for this

from async-redis.

moaxaca avatar moaxaca commented on June 2, 2024 1

@jd20 Sorry for the delay I've been caught up in other projects. I was hoping someone else might take a stab at this but it appears not. I will try to make an effort at resolving this later this week.

Thanks for your patience everybody.

from async-redis.

jd20 avatar jd20 commented on June 2, 2024 1

@kwalski I think this issue can be closed, multi() shouldn't return a promise (exec() should) and not throw an exception, which the PR seems to fix. If exec() works properly (which I think it already does), then the example in the first comment of this issue should work.
Any idea when 1.1.5 will be released? Will be great to have multi() functionality live!

from async-redis.

moaxaca avatar moaxaca commented on June 2, 2024 1

@jd20
https://www.npmjs.com/package/async-redis

from async-redis.

jd20 avatar jd20 commented on June 2, 2024 1

The problem seems to be that the Multi object returned by multi() (or batch()) needs to also be decorated. I took a stab at this with #15.

from async-redis.

MatanYemini avatar MatanYemini commented on June 2, 2024 1

I think that people are still reaching here...

After the fixes that went in, it is possible to wrap the result of exec with Promise, and then you will be sure that the result will include the replies from the multi.

something like:
return new Promise((resolve, reject) => { multi.exec((err, replies) => { if (err) { reject(err); } return resolve(replies); }); });

from async-redis.

moaxaca avatar moaxaca commented on June 2, 2024

@ghostdouble I will write a wrapper for this explicitly. Nice catch ty.

from async-redis.

nissim-kurle avatar nissim-kurle commented on June 2, 2024

hi can you please show how to use watch with multi.
Its not working for me as well.


redisClient.watch(conv, async function(err) {
                                if (err) {
                                    console.log('There was an error while watching .', conversations[0].id);
                                }
                                try {
                                let result = await redisClient.multi().hmset(conv, lastActivity, lastActivityTimeStamp.toString(), helper.participants, JSON.stringify(data.participants)).exec();

                                    if (result === null) {
                                        console.log('The transaction was not performed since the data was accessed by someone else during the transaction and changed.');
                                    }
                                } catch (err) {
                                    console.log('An error occured while performing the update conversation transation in redis');
                                }
                            });

from async-redis.

jd20 avatar jd20 commented on June 2, 2024

Any update on this? Seems multi() is still broken when using the async client. I'm seeing the following:

> require("async-redis").createClient().multi()
Promise {
  <rejected> TypeError: Cannot read property '0' of undefined
      at new Multi (~/testing/node_modules/redis/lib/multi.js:13:30)
      at RedisClient.multi (~/testing/node_modules/redis/lib/individualCommands.js:25:17)
      at Promise (~/testing/node_modules/async-redis/src/index.js:24:14)
      at new Promise (<anonymous>)

from async-redis.

gilad-solter avatar gilad-solter commented on June 2, 2024

@jd20 Sorry for the delay I've been caught up in other projects. I was hoping someone else might take a stab at this but it appears not. I will try to make an effort at resolving this later this week.

Thanks for your patience everybody.

Thanks @moaxaca

from async-redis.

kwalski avatar kwalski commented on June 2, 2024

Can this issue be closed now that this PR is merged?

from async-redis.

gilad-solter avatar gilad-solter commented on June 2, 2024

Can this issue be closed now that this PR is merged?

I don't think so.
This PR only eliminates the error while using .multi, but the issue was about using multi as async.

from async-redis.

andylash avatar andylash commented on June 2, 2024

This PR only eliminates the error while using .multi, but the issue was about using multi as async.

From what I can tell node redis's multi() isn't async and doesn't take a callback as a parameter. Thus having it return a promise doesn't seem correct to mean because it would break chaining. I'm surely open to being wrong, but I don't understand what further change would make multi async as requested without breaking multi and diverting from the node redis interface.

from async-redis.

gilad-solter avatar gilad-solter commented on June 2, 2024

Ohh I see, thanks @andylash for the pr and for looking into this!

from async-redis.

moaxaca avatar moaxaca commented on June 2, 2024

I am leaving this issue open until I implement a more robust solution.

from async-redis.

jd20 avatar jd20 commented on June 2, 2024

Testing with 1.1.5, the resolved value from the promise returned by exec() doesn't seem to correspond to the actual results set, it's just a single boolean value. For example, using the workaround provided by @ghostdouble, the final resolved results is [ 'OK', 0 ], whereas the code below returns just true:

await client.multi().set('a', 'b').hset('h', 'x', 'y').exec()

from async-redis.

prodigga avatar prodigga commented on June 2, 2024

Noticing the same thing here - I can't get the result. It just returns 'true'.

const result = await client.multi().incr(token).expire([token,59]).exec();
console.log(result); //true

ioredis returns an array of results for this operation, so I can check the results of incr and ex operations.

from async-redis.

moaxaca avatar moaxaca commented on June 2, 2024

Fixed in 2.0.0

from async-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.