node.js redis synchronous solution - node.js

I look for the package that allows to work with redis in synchronous manner. The problem is I don't want to rewrite the code for async flow.
The possible solution is
Find synchronous library to work with redis.
Implement a middle layer script in some synchronous language and communicate with this script by synchronous execution operation.
I tried to use synchronize with no success so far.

You may want to give a try at co, which will let you write non-blocking code using almost any existing node library. Here is a specific example using node-redis.
Please note that co requires node 0.11.x (with --harmony flag) or 0.10.x with a wrapper like gnode.

Related

How does Hystrix for NodeJS work despite being single threaded?

hystrixjs is an implementation of Hystrix for NodeJS.
But I'm not able to understand how it works in a single threaded js. How does it handle timing out the task?
The documentation talks about that a bit
Since this library targets nodejs application, it is by far not as
complex as the java implementation (remember... just one thread... no
concurrency, at least most of the time...). So how does it accomplish
the goals outlined above:
wraps all promise-based calls to external systems (or "dependencies") in a "Command"
Does that mean all the library is just run the promise and letting node handle the multi threading part(like network calls being handled by OS threads)?

node.js package written in rust to perform db queries - how to make it efficiently?

I'm a rust newbie, want to write a node.js package related to database querying.
I'm using napi-rs for the package.
In node.js we have own async stuff, in rust we have similar thing called "tokio" for async stuff.
I want to create ORM for node.js, and learn rust at the same time, so idea is to construct queries on node.js side and perform them on rust side, give response back to node.
I see two ways:
Use tokio with tokio-postgres
Not to use tokio, instead to write own database adapter library which will rely on node async functionality and node sockets. Not even sure if I can do this but can try. Not sure if that makes sense.
First way is way more simple, but will it work? Is efficient to include tokio to node.js package?
execute_tokio_future method of napi works just perfect! Details on how to use it I found here: https://forum.safedev.org/t/adventures-in-rust-node-js-and-safe/2959/10
I was able to get benchmark with better results using rust addon than a node library, so the idea paid off.

Handle Async Operations in Node.js

I have been using the async package from NPM inside my Node.js service to run different operations in sequence. Example: when I would like to run functionA, functionB, functionC in sequence. I would use Promise in Node.js, but this means using callbacks which are not that efficient when we have lot of functions which need to run in sequence.
I have recently familiarized myself with Reactive Programming using Observables and this is widely being used in frontend frameworks such as AngularJS and React. I was wondering if Node.js has something similar to that and if there are any better ways to handle async operations in sequence.

Node's coexistance with Boost.Asio

There's a node already doing some repetitive works(like setInterval) and network event handling.
I've built another network library in C++ using Boost.Asio and want to use it from node I explained above(with node-ffi and it works well).
Here's the problem. Node has its own event dispatcher and Boost.Asio too. So, after I've invoked the above C++ library from node, because it blocked, no other node code could not be reached and didn't work anymore.
Can I make them to coexist peacefully...?
Asio's io_service::poll_one() works find in some way but there's a better solution.
node-ffi's Async Library Call is perfect for this situation. It says...
node-ffi supports the ability to execute library calls in a different
thread using the libuv library. To use the async support, you invoke
the .async() function on any returned FFI'd function.

Async access to MongoDB using Aleph/Lamina

I have been reading about Clojure for some time and I'm considering it as a replacement to Node.js (which I have used for another project). The most promising library seems to be Aleph/Lamina, which unfortunately doesn't have nearly as many examples as Node. My questions are:
How can I process requests with a chain of async operations, such as reading a document from MongoDB, doing some calculations, saving the new document and sending it in the response? I was not able to write it from the examples in Lamina wiki page. It sounds like a pretty common use case and I was surprised not to found any code showing it. It would be great if you could show me some sample code.
Is this setup adequate for a heavy-load server (say, tens of thousands requests per second)? I can't afford to create one thread for each new request, so I need something similar to the Node approach.
Is there any example of a medium- or large-sized company out there using any of this?
Is there any better Clojure replacement to Node (besides Aleph/Lamina)? Perhaps Clojurescript targetting Node? My client is not written in Javascript, so using the same language in both client and server is not an advantage in my case.
Thanks!
Few pointers:
You need to look at Aleph which builds HTTP abstractions over Lamina channels abstraction.
Reading and writing docs to MongoDB can be async but the library should provide this. In Node.js the MongoDB library has to be async other wise it would screw up the Node programming model, where as this is not the case with Clojure so most probably the Clojure MongoDB library provides non-async function.
Async operations are only helpful in case of IO i.e reading/writing to mongodb, sending response back etc. Generation computations are CPU bound operations and has nothing to do with async model.
Vert.x is Java world Node.js. Clojure support is on roadmap. I would prefer Aleph as you can play in async and non-async world as required.

Resources