最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get number of connections in Redis using Node.js? - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 3

CLIENT 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
发布评论

评论列表(0)

  1. 暂无评论