Last active
August 29, 2015 14:21
-
-
Save muratatak77/1930add08059f910c892 to your computer and use it in GitHub Desktop.
node redis hmset and hgetall example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
var orders = []; | |
var tracking_grp_orders = []; | |
var orders_count = 0 ; | |
var email = req.user.local.email; | |
logger.info(utils.calling(filename,methods.index.value),' / user : ', email); | |
logger.info("All orders displaying / user : ", email); | |
var orders_full_url = req.protocol + '://' + req.get('host') + req.originalUrl; | |
var tracking_orders_full_url = "tracking_" + orders_full_url; | |
var orders_count_full_url = "orders_count_" + orders_full_url; | |
var page = (req.param('page') > 0 ? req.param('page') : 1) - 1; | |
var perPage = 5; | |
var options = { | |
perPage: perPage, | |
page: page | |
}; | |
client.hgetall("orders_full_url_hash", function(err, result_hash_order) { | |
if (result_hash_order != null | |
&& result_hash_order[orders_full_url] != null | |
&& (utils.undefined_check(result_hash_order) != "") | |
&& (utils.undefined_check(result_hash_order[orders_full_url]) != "")) { | |
logger.info("orders_full_url_hash vast cache bulundu. Direk sayfa gonderiliyor. : ", orders_full_url); | |
tracking_grp_orders = JSON.parse(result_hash_order[tracking_orders_full_url]); | |
orders_count = result_hash_order[orders_count_full_url]; | |
orders = JSON.parse(result_hash_order[orders_full_url]); | |
orders.forEach(function(ord, index) { | |
tracking_grp_orders.forEach(function(trc, index) { | |
if (ord._id == trc._id) { | |
ord.tracking_temp = trc; | |
} | |
}) | |
}) | |
logger.info("Rendering orders/index . User :", email); | |
res.render('orders/index', { | |
orders: orders, | |
moment: moment, | |
page: page + 1, | |
pages: Math.ceil(orders_count / perPage), | |
page_href: "orders" | |
}); | |
} else { | |
Order.count().exec(function(err, orders_count){ | |
Order.list_web(options , function(err , orders){ | |
// var trackings_grp = []; | |
Tracking.group(function(err , tracking_grp_orders){ | |
// trackings_grp = tracking_grp_orders; | |
orders.forEach(function(ord, index) { | |
tracking_grp_orders.forEach(function(trc, index) { | |
if (ord.id == trc._id) { | |
ord.tracking_temp = trc; | |
} | |
}) | |
}) | |
// res.end(); | |
res.render('orders/index', { | |
orders: orders, | |
moment: moment, | |
page: page + 1, | |
pages: Math.ceil(orders_count / perPage), | |
page_href: "orders" | |
}); | |
client.hmset("orders_full_url_hash", orders_full_url, JSON.stringify(orders), | |
tracking_orders_full_url, JSON.stringify(trackings_grp), | |
orders_count_full_url , orders_count, | |
function(err , result_orders_cache){ | |
if (result_orders_cache) { | |
logger.info("orders_full_url_hash hashine orders eklendi.key : ", orders_full_url); | |
logger.info("orders_full_url_hash hashine trackings_grp eklendi.key : ", tracking_orders_full_url ); | |
logger.info("orders_full_url_hash hashine orders_count eklendi. key : ", orders_count_full_url); | |
logger.info("Rendering orders/index . User :", email); | |
res.render('orders/index', { | |
orders: orders, | |
moment: moment, | |
page: page + 1, | |
pages: Math.ceil(orders_count / perPage), | |
page_href: "orders" | |
}); | |
} | |
}); | |
}); | |
}); | |
}); | |
} | |
}); | |
} catch (err) { | |
logger.error(utils.error_info(__filename, err), ". User : ", email); | |
res.render('orders/index', { | |
errors: utils.errors(err) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment