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);
以上代码返回' undefined'即使我的redis服务器上有频道。我正确使用它?如果是这样,是否有其他方法可以访问redis服务器上可用的频道。
我正在使用' redis '封装
答案 0 :(得分:0)
您需要使用const data = {
"file_1": {
"configurations": {
"config_1": {
"config_explanation": "TYPE",
"value": "xx",
"value_explanation": "XX"
},
"config_2": {
"config_explanation": "SOME",
"value": "YY",
"value_explanation": "DOSA"
},
},
},
"file_2": {
"configurations": {
"config_1": {
"config_explanation": "TYPE",
"value": "ZZ",
"value_explanation": "PP"
},
"config_2": {
"config_explanation": "SOME",
"value": "GG",
"value_explanation": "BB"
},
},
},
};
const formatted = {};
const fileKeys = Object.keys(data);
fileKeys.forEach((file) => {
const config = data[file].configurations;
const configKeys = Object.keys(config);
configKeys.forEach((key) => {
formatted[key] = Object.assign({},
formatted[key],
{
config_explanation: config[key].config_explanation,
}
);
if (!formatted[key].files) {
formatted[key].files = [];
}
formatted[key].files.push({
file,
value: config[key].value,
value_explanation: config[key].value_explanation,
});
});
});
console.log(formatted);
,因为驱动程序不直接支持send_command
命令:
PUBSUB