I think you want to take a lock out in the DB to protect your critical
section of code. I thought that's something Redis supported.

I'm sure performance would be better if the critical section of code
was on the DB itself. Mongo is probably not a good choice as I think
Mongo store procedures block the whole DB (and don't work with
sharing), so you would want a dedicated Mongo instance just for that
one collection.

Chris

On Feb 16, 7:09 am, HG <[email protected]> wrote:
> Hi!
>
> I created a small counting algorithm first in JavaScript. Seems to
> work ok. But this is of course single threaded and I could only store
> snapshots of it to DB. So I started thinking that what if I use Redis
> directly as the memory. Then I could have multiple threads or even
> servers running against it.
>
> However, the algorithm limits the stuff that is kept in memory. So,
> basically I need to do something like this:
>
> redis.zincrby(key, 1, str, function (err, reply) {
>     redis.zcard(key, function (err, N) {
>     If (N > maxSize) {
>         // do stuff with the keys, including delete some (this is a
> few callbacks here...)
>     }}
>
> I.e. I add counters (zincrby ands new one if it doesn't exists), but
> if there are too many as a result of that, I need to do some cleaning.
>
> But obviously, the whole thing works in threaded situation only if
> that code is blocking. So, I can't run multiple servers against redis
> like this or this whole code should block redis (I guess I could store
> this kind of procedure to MongoDB...). But is there even a way to
> block single node.js event loop for this? I know that would not be
> wise (for keeping up the speed), but I'm just trying to learn how to
> do this kind of stuff? Should all cases where I need blocking with the
> DB done with stored procedures in the DB?
>
> --
> HG.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to