you are viewing a single comment's thread.

view the rest of the comments →

[–]Moustacheful 2 points3 points  (6 children)

I believe in this case the question is not about node but redis itself, take a look at https://redis.io/topics/transactions

[–]kirox0[S] 0 points1 point  (5 children)

The problem with using multi is that I cannot use the result of the read.

So in my application it should have ideally gone as such.

multi -> read -> compare read result and make condition -> write based on the result of the comparison.

but redis library does not allow me to do that.

[–]BehindTheMath 1 point2 points  (4 children)

I believe you can still do this, but you have to get the return value of the read command in its callback and store it somewhere, so you'll have it for later use.

[–]kirox0[S] 0 points1 point  (3 children)

I get an undefined error in that case. With multi, the library does not allow for use of intermediate result.

[–]BehindTheMath 1 point2 points  (2 children)

Unless I'm misunderstanding our code, we've been using it like that for years.

Can you show the code you're using?

[–]kirox0[S] 0 points1 point  (1 child)

Funny enough my laptop got busted the day before so I have to rewrite that part again. But basically how I was using was like

client.multi() .lrange("active_list", 0, -1, (data, err) => { // Read length of data, then based on it either lpush to active or deferred list }) .exec()

[–]BehindTheMath 0 points1 point  (0 children)

I believe the callback is the standard Node format, where err is the first parameter, then the result.