社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Redis

使用nodejs在json redis中设置函数类型

Shubham Jain • 7 年前 • 2342 次点击  

嗨,我正在尝试使用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 评估。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30843
文章 [ 1 ]  |  最新文章 7 年前