Comments (18)
here's a PR for this
from async-redis.
@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.
@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.
@jd20
https://www.npmjs.com/package/async-redis
from async-redis.
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.
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.
@ghostdouble I will write a wrapper for this explicitly. Nice catch ty.
from async-redis.
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.
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.
@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.
Can this issue be closed now that this PR is merged?
from async-redis.
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.
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.
Ohh I see, thanks @andylash for the pr and for looking into this!
from async-redis.
I am leaving this issue open until I implement a more robust solution.
from async-redis.
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.
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.
Fixed in 2.0.0
from async-redis.
Related Issues (20)
- node-redlock conflits with async-redis HOT 3
- decorate without mutating HOT 1
- Typescript type definitions. HOT 7
- Interrupted watch-ed transaction returns true instead of null HOT 1
- connect-redis conflicts with async-redis HOT 1
- Build failing HOT 2
- doesnt work with redis-rejson HOT 1
- publish latest HOT 1
- NOAUTH Authentication required (How to handle passwords?) HOT 2
- redis.print is not working
- Update redis HOT 3
- Typescript compiler imports index.d.ts instead of index.js HOT 6
- createClient method not always behaving as expected HOT 1
- v2 completely broke several connections to single redis HOT 2
- createClient not work after quit HOT 2
- tsc compile errors
- Modifiers doesn't work HOT 1
- Types are incorrect HOT 2
- createClient blocks HOT 1
- hgetall function undefined return
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-redis.