嗨,我正在尝试使用ioredis在redis中存储JSON。这个JSON也包含一个函数。我的JSON的结构如下:
var object = {
site1: {
active: true,
config1:{
// Some config in JSON format
},
config2: {
// Some other config in JSON format
},
determineConfig: function(condition){
if(condition) {
return 'config1';
}
return 'config2';
}
}
}
我正在使用ioredis将此JSON存储在redis中:
redisClient.set(PLUGIN_CONFIG_REDIS_KEY, pluginData.pluginData, function (err, response) {
if (!err) {
redisClient.set("somekey", JSON.stringify(object), function (err, response) {
if (!err) {
res.json({message: response});
}
});
}
});
当我这样做的时候
determineConfig
从中截断键
object
作为
JSON.stringify
如果类型为“函数”,则将其移除。有什么方法可以把这个函数存储在redis中,一旦我从redis中得到数据,就可以执行这个操作吗?我不想将函数存储为字符串,然后使用
eval
或
new Function
评估。