Javascript 如果我过早地在robot.brain中设置了一个值,它就会被hubot redis brain覆盖

Javascript 如果我过早地在robot.brain中设置了一个值,它就会被hubot redis brain覆盖,javascript,hubot,Javascript,Hubot,如果我在脚本的模块.exports主体中的robot.brain中初始化属性,则该属性不起作用(请参见下面的代码)。如果我在响应期间初始化它,它就会工作。我关于它被hubot redis大脑覆盖的假设正确吗?我该如何用一种好的方式修复它 module.exports = (robot) => { robot.logger.debug("Setting the fucking property"); robot.brain.set("stringproperty", "str

如果我在脚本的
模块.exports
主体中的
robot.brain
中初始化属性,则该属性不起作用(请参见下面的代码)。如果我在响应期间初始化它,它就会工作。我关于它被hubot redis大脑覆盖的假设正确吗?我该如何用一种好的方式修复它

module.exports = (robot) => {
    robot.logger.debug("Setting the fucking property");
    robot.brain.set("stringproperty", "stringvalue");
    robot.logger.debug("SET!");
    // logs these two entries before 'INFO hubot-redis-brain: Data for hubot brain retrieved from Redis'

    const respondAndLog = (res, message) => {
        robot.logger.debug("Responding: " + message);
        res.reply(message);
    };

    robot.respond(/get_stringproperty/, (res) => {
        respondAndLog(res, `${robot.brain.get("stringproperty")}`);
        // prints null. WTF?
    });

    robot.respond(/get_laterinitializedproperty/, (res) => {
        robot.brain.set("laterinitializedproperty", "laterinitializedvalue");
        respondAndLog(res, `${robot.brain.get("laterinitializedproperty")}`);
    // prints laterinitializedproperty, works OK
    });
};

hubot redis brain
使
机器人。当数据从redis加载或初始化时,brain
会发出一个
“已连接的”
事件,请参见[第55行和第59行]。因此,应如何修复它:

robot.brain.on("connected", () => {
    robot.logger.debug("Setting the fucking property");
    robot.brain.set("stringproperty", "stringvalue");
    robot.logger.debug("SET!");
});

hubot redis brain
使
机器人。当数据从redis加载或初始化时,brain
会发出一个
“已连接的”
事件,请参见[第55行和第59行]。因此,应如何修复它:

robot.brain.on("connected", () => {
    robot.logger.debug("Setting the fucking property");
    robot.brain.set("stringproperty", "stringvalue");
    robot.logger.debug("SET!");
});