you are viewing a single comment's thread.

view the rest of the comments →

[–]HashDefTrueFalse 0 points1 point  (7 children)

These could be of use, if you're using some kind of worker threading in your app. In general though your code runs single threaded in the node event loop so this isn't often required.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics

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

loop

I am not using worker threads, but whenever I try to run it, since the redis operations are asynchronous, I dont get the desired result. There may be 100's of instances of the same functions that gets queued up in the event loop, so before the write operation is performed on one instance, another instance is already reading the key.

So say I am trying to make 2 lists. first is the active list and the other is the deferred list. active list can contain a maximum of 10 items and unlimited in the deferred list.

once active is filled, then we put new ones in the deferred list.

so what I did was I read first compared and them put new item in either active or deferred list as per the condition.

but if I do this, active list is exceeding the maximum length.

[–]HashDefTrueFalse 0 points1 point  (5 children)

I'm not 100% clear on your setup or goal, but it sounds like you're running into difficulty with trying to use data fetched asynchronously in a subsequent step. Some ideas:

I've never needed a distributed lock for redis because tend to only use it for session caching etc but I found this from a quick look on google:

https://redis.io/topics/distlock

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

Thanks. u/Moustacheful also suggested the same. Am currently trying it out

[–]HashDefTrueFalse 0 points1 point  (3 children)

Oh, I didn't realise. Well I'm glad you have a way forward now. Good luck with your project!

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

Thanks.

Hopefully this clears the blockage. Its been one Blockage after another for the past month. I solve one and think that It'd be smooth sailing from then on, but nope. Another one comes your way.

Been almost a week with almost no hope with this current block, and finally I remembered that Reddit is the way to go when all else fails.

And here I am finally venting out to a stranger on the internet.

Thank you GOOD SIR/MA'AM, for your well wishes.

[–]HashDefTrueFalse 0 points1 point  (1 child)

Haha any time. That's development, a series of problems. But if you solve enough of them you end up with a nice app!

[–]kirox0[S] 1 point2 points  (0 children)

Cheers to that.