有没有办法检查当前连接到 Redis 数据库的连接数?
const redis = require('redis');
var client = redis.createClient(port, host);
client.on('connect', () => {
//Display how many current connections are to Redis
console.log( numberOfRedisClients );
});
有没有办法检查当前连接到 Redis 数据库的连接数?
const redis = require('redis');
var client = redis.createClient(port, host);
client.on('connect', () => {
//Display how many current connections are to Redis
console.log( numberOfRedisClients );
});
const Redis = require("ioredis");
let client = new Redis();
async function my_function(){
console.log(await client.send_command('CLIENT', 'LIST'))
}
输出:
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
总连接数
,则可以使用 INFO 命令。 INFO clients
将打印类似于此内容,而 connected_clients
就是您要查找的内容。# 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
const Redis = require("ioredis");
const redis = new Redis();
async function clients() {
console.log(await redis.info('clients'));
}
clients();
connected_clients
排除副本连接 - 因此方程式可以是(info clients
中的总行数 - connected_slaves
(您可以从 info replication
中获取)= connected_clients
)。@VardanBetikyan - Ersoycmd=client
计数是正确的。尽管connected_clients
也将其他cmd
类型(info、subscribe、NULL)计算为客户端连接。 - Vardan Betikyan