Hi I am trying to store a JSON in redis using ioredis. This JSON comprises of one function too. The structure of my json is something like:
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';
}
}
}
I am using IOredis to store this json in 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});
}
});
}
});
When I am doing this the determineConfig
key is truncated from the object
as JSON.stringify
removes it if the type is function. Is there some way I can store this function in redis and excute that once I get the data back from redis. I do not want to store the function as a string and then use eval
or new Function
to evaluate.