有没有办法检查 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 documentation尝试这个 :
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
关于javascript - 如何使用 Node.js 获取 Redis 中的连接数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65166098/