【问题标题】:Sails.js How to load session and create, check, destroy?Sails.js 如何加载会话并创建、检查、销毁?
【发布时间】:2013-11-18 05:41:16
【问题描述】:

在配置 session.js 中我启用了 redis 在此之前我已经安装了这两个东西......

npm install connect-redis

npm install express

           adapter: 'redis',
          //
          // on localhost is expected.
          // Read more about options at: https://github.com/visionmedia/connect-redis
          //
           host: 'localhost',
           port: 6379,
           ttl: 3600,
           db: 0,
           pass: '',
           prefix: 'sess:'

在控制器 2 中

//在session中赋值并重定向到controller1 req.session.error = "未找到类别";

//错误 TypeError:无法设置未定义的属性“错误”

            module.exports = {

              load_word: function(req, res){ 
                 var async = require('async');
                 var express = require('express');
                 var RedisStore = require('connect-redis')(express);

                 async.waterfall([
                        function(callback){
                            Category.findOne().where({keyword:req.param('keyword')}).done(function(err,category){
                                if(category==undefined){ 
                                    req.session.error = "category Not found";
                                    res.redirect('home');
                                }else{
                                    category_id = category.id;
                                }
                                /*Word.findOne().where({id:category_id}).done(function(err,word){ 

                                });*/
                            });
                        },

控制器 1

console.log(req.session.error);

           module.exports = {

          /**
           * Action blueprints:
           *    `/home/index`
           *    `/home`
           */
           index: function (req, res) {
            var async = require('async');
            var express = require('express');
            var RedisStore = require('connect-redis')(express);
            var data = new Object();

                console.log(req.session.error);

如何解决?

【问题讨论】:

    标签: node.js sails.js node-redis


    【解决方案1】:

    检查类别是否未定义或不使用 if(typeof(category)!='undefined){}

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      相关资源
      最近更新 更多