Note that there are some explanatory texts on larger screens.

plurals
  1. PONodeJS + Redis + HTTP Get
    primarykey
    data
    text
    <p>I'm currently getting data from my database by the way of PHP using Nodejs. The problem is that the script that I want to execute after grabbing datas is actually executing directly after the instance of my grabing function and I get everytime an error saying that my datas are undefined.</p> <p>Here is my code :</p> <pre><code>var http = require('http'), redis = require("redis"); client = redis.createClient(); client.on("error", function (err) { console.log("Error " + err); }); var sessionData; // Check if we have session create with sessionID gived before (hash) client.get('sessions:'+sessionId, function (err, result) { var resData; //Check if we have session with the session id // If we have not execute function to get the data if(err || !result) { executefunction(get_sess_data,sessionId); } // If we have, get it from redis else { resData = result; console.log(resData); } // settings session data with the result sessionData = JSON.parse(resData); }); // Execute function with sessionid as value function executefunction(someFunction, value) { someFunction(value); } // Getting data from database (using script from Codeigniter) var get_sess_data = function(response) { var options = { host: 'www.example.dev', port: 80, path: '/index.php/user_session/decrypt?id='+sessionId }; http.get(options, function(result) { result.on("data", function(chunk) { client.setex('sessions:'+sessionId, 21600, chunk.toString()); }).on('error', function(e) { console.log("Got error: " + e.message); }); result.end(response); }); }; </code></pre> <p>FYI, I know the code to grab data is working because I can return them if I don't execute the following script "sessionData = JSON.parse(resData);" even if I place it in my if statement.</p> <p>I'm stuck for hours on it. If anyone have an issue, let me know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload