Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: How Many Redis Clients?

In Node.js, would it be best to do a createClient() for each individual HTTP request or user, or would it be better to re-use the same client for all requests? Do you still get the speed of several parallel clients with just one?

like image 368
Kevin McTigue Avatar asked Sep 26 '11 21:09

Kevin McTigue


People also ask

How many Redis clients are there?

Redis can handle many connections, and by default, Redis has a maximum number of client connections set at 10,000 connections. You can set the maximum number of client connections you want the Redis server to accept by altering the maxclient from within the redis.

Why Redis is used in Node JS?

Redis, an in-memory database that stores data in the server memory, is a popular tool to cache data. You can connect to Redis in Node. js using the node-redis module, which gives you methods to retrieve and store data in Redis.

What are Redis clients?

Redis accepts clients' connections on the configured listening TCP port and on the Unix socket, if enabled. When a new client connection is accepted, the following operations are performed − The client socket is put in non-blocking state since Redis uses multiplexing and non-blocking I/O.

What is Jedis client?

Overview. In this tutorial, we'll introduce Jedis, a client library in Java for Redis. This popular in-memory data structure store can persist on a disk as well. It's driven by a keystore-based data structure to persist data, and can be used as a database, cache, message broker, etc.


1 Answers

In Node.js, would it be best to do a createClient() for each individual HTTP request or user, or would it be better to re-use the same client for all requests?

You should reuse the redis client connection and persist it during the lifetime of your program since establishing a new connection have some initial overhead which can be avoided with already connected client.

Do you still get the speed of several parallel clients with just one?

You might get some performance improvements with a pool of several parallel clients (limited number, not dedicated connection for each individual HTTP request or user), but the question is how would you deal with the concurrency of executed commands. Although redis is built to handle hundreds or thousands of simultaneously connected clients, connection pooling is something which, I think, should be controlled by the client library you are using. However you should use two parallel connections if you are simultaneously using redis for listening on some pub/sub channel and at the same time executing normal commands.

like image 160
yojimbo87 Avatar answered Nov 01 '22 23:11

yojimbo87