Skip to content

Instantly share code, notes, and snippets.

@paul-english
Created October 6, 2010 20:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save paul-english/614068 to your computer and use it in GitHub Desktop.
Save paul-english/614068 to your computer and use it in GitHub Desktop.
// helper function that goes inside your socket connection
client.connectSession = function(fn) {
var cookie = client.request.headers.cookie;
var sid = unescape(cookie.match(/connect\.sid=([^;]+)/)[1]);
redis.get(sid, function(err, data) {
fn(err, JSON.parse(data));
});
};
// usage
client.connectSession(function(err, data) {
console.log(data);
});
@davej
Copy link

davej commented Jan 17, 2011

Thanks. You should wrap the sid in unescape() though to avoid potential errors.

@paul-english
Copy link
Author

Good call, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment