0

in connect-redis to return session value use .get(sid, callback) but it always return null so I think its not save in redis but I check it session save in redis correctly after investigation find problem is with Sid see /connect-redis/lib/connect-redis.js

  RedisStore.prototype.get = function(sid, fn){
   sid =this.prefix + sid;
    debug('GET "%s"', sid);

    console.log('lib');
    console.log(sid);

    this.client.get( sid , function(err, data){

      if (err) return fn(err);
      if (!data) return fn(null,'');
      var result;
      data = data.toString();
      debug('GOT %s', data);
      try {
        result = JSON.parse(data); 
      } catch (err) {
        return fn(err);
      }

      return fn(null, result);
    });
  };

if I but sessionID as string it will return session

  RedisStore.prototype.get = function(sid, fn){

  //  sid =this.prefix + sid;
    debug('GET "%s"', sid);

    console.log('lib');
    console.log(sid);

    this.client.get( 'lweUw//EdbygbGr/2gAZt0kb' , function(err, data){

      if (err) return fn(err);
      if (!data) return fn(null,'');
      var result;
      data = data.toString();
      debug('GOT %s', data);
      try {
        result = JSON.parse(data); 
      } catch (err) {
        return fn(err);
      }

      return fn(null, result);
    });
  };

Note:

typeof(sid) is string even if add qoute to sid like this "\'sid\'" it will return null

1
  • It would be helpful to see your callback function. Commented Aug 5, 2013 at 9:22

1 Answer 1

2

The callback takes the form callback(err, data). If there is no error, the first parameter will always be null. The real response is in the second parameter.

See: return fn(null, result); in .get().

Sign up to request clarification or add additional context in comments.

2 Comments

no data return the response it return from if condition see (!data) return fn(null,'');
You said it returned null in your question. An empty string is not null. Is the type of the return value a string?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.