I'm a PHP programmer and I started developing with NodeJS to optimize my web application and reduce server resources.
I'm no expert in Javascript, therefore, I have several doubts in syntax and code.
I developed the following code:
var redis = require("redis"), client = redis.createClient();
client.on("error", function (err) {
logger.error("Couldn“t connect Redis");
});
client.on("connect", function() {
client.get("user:ID", function (err, reply) {
if(reply) {
// CODE
}
});
});
I want that to continue executing the code when there is no key and I think putting various IF not the most optimized way.
EXAMPLE:
client.on("connect", function() {
client.get("user:ID", function (err, reply) {
if(reply) {
// ROUTINE
}
});
});
or
client.on("connect", function() {
client.get("user:ID", function (err, reply) {});
});
if (key) {
// Code 1
}
// Code
if (key) {
// Code 2
}
............
Does something similar to php DIE to finish the routine? How could develop and optimize this? Thank you.
Regards