<commit_before>// This server can be used to test the module
// The easiest way is probably to run it while there is an instance of the redis 
// Delete this file before 
// To run it do node ./example/example.js
var Hapi = require('hapi');
var RedisSessionReader = require('../index');
var sessionSecret = "IMPORT_SECRET_KEY_HERE"; // Don't commit the real secret key!

var server = new Hapi.Server();
server.connection({ 
  host: 'localhost',
  port: 8000,
  routes: {
    cors: true
  }
});

// Unsign and decode the cookie from the browser
// In a real example, you would parse this from the cookie
var rawSignedSessionId = 's%3AK-5uqkQChDuf5b5dAytqfqm8.dvl08QCN1ydR5TT7uul9v0B3e3Z7ukyK%2Bhx34gFaDTQ';

var sid = RedisSessionReader.unsignCookieSid(rawSignedSessionId, sessionSecret);
console.log('querying for sid: ', sid);

RedisSessionReader.connectHapiServerToRedis(server, _doStuffAfterConnectingToRedis);

function _doStuffAfterConnectingToRedis (err, status) {
  if (err) {console.log(err); return;}
  RedisSessionReader.getSessionIdFromRedis(sid, server.plugins['hapi-redis'].client, handleUserIdRes);

  function handleUserIdRes (err, userId) {
    if (err) {console.log(err) ; return;}
    console.log('server got userId: ', userId);
  }
}<commit_msg>update example with new fn signature<commit_after>// This server can be used to test the module
// The easiest way is probably to run it while there is an instance of the redis 
// Delete this file before 
// To run it do node ./example/example.js
var Hapi = require('hapi');
var RedisSessionReader = require('../index');
var sessionSecret = "IMPORT_SECRET_KEY_HERE"; // Don't commit the real secret key!

var server = new Hapi.Server();
server.connection({ 
  host: 'localhost',
  port: 8000,
  routes: {
    cors: true
  }
});

// Unsign and decode the cookie from the browser
// In a real example, you would parse this from the cookie
var rawSignedSessionId = 's%3AK-5uqkQChDuf5b5dAytqfqm8.dvl08QCN1ydR5TT7uul9v0B3e3Z7ukyK%2Bhx34gFaDTQ';

var sid = RedisSessionReader.unsignCookieSid(rawSignedSessionId, sessionSecret);
console.log('querying for sid: ', sid);

redisOptions = {
  host: 'localhost',
  port: 6379
};

RedisSessionReader.connectHapiServerToRedis(server, sessionSecret, 'connect.sid.1.0', redisOptions, _doStuffAfterConnectingToRedis);

function _doStuffAfterConnectingToRedis (err, status) {
  if (err) {console.log(err); return;}
  RedisSessionReader.getSessionIdFromRedis(sid, server.plugins['hapi-redis'].client, handleUserIdRes);

  function handleUserIdRes (err, userId) {
    if (err) {console.log(err) ; return;}
    console.log('server got userId: ', userId);
  }
}
{'fraction_non_alphanumeric': 0.11190655614167294, 'fraction_numerical': 0.018839487565938208, 'mean_word_length': 4.939597315436242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7204076', 'n_tokens_mistral': 915, 'n_tokens_neox': 906, 'n_words': 249}