Is there a way to check how many current connections there are to the Redis database?
const redis = require('redis');
var client = redis.createClient(port, host);
client.on('connect', () => {
//Display how many current connections are to Redis
console.log( numberOfRedisClients );
});
Is there a way to check how many current connections there are to the Redis database?
const redis = require('redis');
var client = redis.createClient(port, host);
client.on('connect', () => {
//Display how many current connections are to Redis
console.log( numberOfRedisClients );
});
Share
Improve this question
edited Dec 6, 2020 at 8:57
Vardan Betikyan
asked Dec 6, 2020 at 8:26
Vardan BetikyanVardan Betikyan
3945 silver badges24 bronze badges
2 Answers
Reset to default 3CLIENT LIST returns information and statistics about the client connections server in a mostly human readable format as @babak stated in the answer.
If you just need to get total number of connections
you may use INFO mand. INFO clients
will print something like this and connected_clients
would be what you are looking for.
# Clients
connected_clients:2
client_recent_max_input_buffer:8
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
The following code do the work;
const Redis = require("ioredis");
const redis = new Redis();
async function clients() {
console.log(await redis.info('clients'));
}
clients();
according to redis documentation try this :
const Redis = require("ioredis");
let client = new Redis();
async function my_function(){
console.log(await client.send_mand('CLIENT', 'LIST'))
}
the output :
id=24 addr=127.0.0.1:47962 fd=8 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=info
id=25 addr=127.0.0.1:47964 fd=9 name= age=0 idle=0 flags=P db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=subscribe
id=26 addr=127.0.0.1:47966 fd=10 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client