通过node js中的'redis'包访问redis服务器上可用的redis通道
Accessing redis channels available on the redis server through 'redis' package in node js
var redis = require('redis');
var redisClient = redis.createClient({host : 'localhost', port : 6379});
var x = redisClient.pubsub.channels //Cuz this is similar to PUBSUB CHANNELS
console.log(x);
上面的代码 returns 'undefined' 即使我的 redis 服务器上有通道。我在正确使用它吗?如果是这样,有没有其他方法可以访问redis服务器上可用的频道。
我正在使用“redis”包。
您需要使用 send_command
,因为驱动程序不直接支持 PUBSUB
命令:
redisClient.send_command('PUBSUB', [ 'CHANNELS' ], function(err, channels) {
if (err) {
console.log('Received an error:', err);
} else {
console.log('Channels:', channels);
}
});
var redis = require('redis');
var redisClient = redis.createClient({host : 'localhost', port : 6379});
var x = redisClient.pubsub.channels //Cuz this is similar to PUBSUB CHANNELS
console.log(x);
上面的代码 returns 'undefined' 即使我的 redis 服务器上有通道。我在正确使用它吗?如果是这样,有没有其他方法可以访问redis服务器上可用的频道。
我正在使用“redis”包。
您需要使用 send_command
,因为驱动程序不直接支持 PUBSUB
命令:
redisClient.send_command('PUBSUB', [ 'CHANNELS' ], function(err, channels) {
if (err) {
console.log('Received an error:', err);
} else {
console.log('Channels:', channels);
}
});