gpt4 book ai didi

javascript - 如何使用 Node.js 获取 Redis 中的连接数?

转载 作者:行者123 更新时间:2023-12-03 12:16:53 28 4
gpt4 key购买 nike

有没有办法检查 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com