Comments (5)
The idea is to create a client once and reuse it across many logical application requests.
You do not really need a connection pool as everything in Node.js involving I/O including this Redis client is asynchronous. You simply fire off your request and then when the response is ready you are good to go. With this, your app will be handling many concurrent application requests.
Make sense?
from redis-node-client.
I could be wrong but I am not sure. Let's imagine that we are processing 2 incoming HTTP requests coming in pretty much at the same time. The first one uses the client and invoke a GET passing in key1 and passing in a callback function cb1. Under the cover, your client uses a connection and issues a command. While it is waiting for the response, the request for the second client gets processes. If that request uses the same client with a different key and different callback function, I am not sure how your feed parser can differentiate the response from each request separately (specially given that some redis response are coming in as part of multiple chunks). The stream will emit multiple "data" events but I do not think that the order is enforced and it is not clear to me how each data is correlated with the first and second request. The only way I see to do that is to dedicate a connection to a request and wait until the callback for request is complete before we send another request using that same connection.
Have you had the chance to look at how the memcachejs node client is implemented? http://github.com/jketterl/memcachejs The seem to have gone down the path of implementing a Pool, Connection and Request abstraction.
from redis-node-client.
Redis responds to requests per client in FIFO order. Thus, redis-node-client stores a callback per request/command. When each response from Redis is sent to the redis-node-client, it pops the callback and calls it back with the response.
In your example, the 2 requests are sent to Redis in the order received, and the responses are dispatched in the same order.
The point of the callback is that your application can perform other I/O (reading a file, queueing requests, calling HTTP client requests to some remote server, etc) at the same time waiting for Redis to respond.
I haven't looked at memcachejs. There's no need for a connection pool to a single Redis instance given the above. Connection pools make sense for calls that block; redis-node-client calls do not block. Also, memcache is distributed. Redis is not and is moreover single-threaded.
from redis-node-client.
It make sense now. Thanks for the clarification. Two follow up questions:
-
Do you know if it is possible to gzip.compress content before caching it in redis?
-
I noticed in the ReplyParser.feed that you are currently iterating byte by byte over the inbound buffer. Do you know if it would be possible to optimize both the allocation of valueBuffer and the copy in the case of BULK responses where we now the expected length size? We are storing and retrieving JSON structures with are 30-50K in size and if possible those optimization could end up having a big impact.
Thank again for the coaching!
Edwin
from redis-node-client.
There exists a node-compress module I believe. See the node modules page in the node.js repo's wiki here on github.
The reason for the byte-by-byte scanning is to make a stateful parser. We are in no way guaranteed that a chunk received by a "data" event contains a full Redis reply. At any byte the end of the chunk could be reached. I don't imagine 30K-50K values having that much overhead given that the Buffer is written in C++ and that the loop is quite tight otherwise. But as always with performance concerns, don't guess, benchmark! If you do find a performance problem, please open an issue.
Thanks!
from redis-node-client.
Related Issues (20)
- Can't figure out how this is supposed to work without some ugly code HOT 4
- npm HOT 4
- client.get -> TypeError: Cannot read property 'length' of undefined HOT 9
- Operations returning empty lists/sets should return [] instead of null
- TypeError: Cannot read property 'length' of null HOT 4
- Register package with npm HOT 1
- Compatible with node v0.1.100 ? HOT 4
- HSETNX HOT 3
- ./index.js HOT 3
- Register package with NPM HOT 4
- node test/test.js -q FAILED (nodejs 0.1.102 + redis 1.3.17 + redis-node 0.3.5) HOT 5
- non-standard intepretation of trailing commas
- Are command arguments sanitized? HOT 1
- Incompatible with latest Node HOT 3
- test/test.js throwing has no method 'utf8Write' error HOT 10
- "testZINTER" "ERR unknown command 'zinter'" HOT 1
- "ERR unknown command '*2"
- Cannot read property 'length' of undefined HOT 3
- "noconnection" event not emitted if Redis goes away after the first connection
- Server never calls back on Node 0.2.4
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 redis-node-client.