Created
December 2, 2011 14:00
-
-
Save bytespider/1423328 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var util = require("util"); | |
| exports.show = { | |
| json: function (req, res) { | |
| res.send(JSON.stringify(req.item)); | |
| }, | |
| default: function (req, res) { | |
| this[req.format](req, res); | |
| } | |
| }; | |
| exports.load = function (id, callback) { | |
| var redis = require("redis"), | |
| client = redis.createClient(); | |
| client.smembers("items", function (err, ids) { | |
| var items = []; | |
| if (ids.length <= 0) { | |
| callback(err, items); | |
| client.quit(); | |
| } | |
| var len = ids.length; | |
| for (var i = 0; i < len; i++) | |
| { | |
| client.multi() | |
| .get("items:" + ids[i] + ":title") | |
| .get("items:" + ids[i] + ":description") | |
| .smembers("items:" + ids[i] + ":keywords") | |
| .smembers("items:" + ids[i] + ":categories") | |
| .exec(function (err, replies) { | |
| items.push({ | |
| id: ids[i], | |
| title: replies[0], | |
| description: replies[2], | |
| keywords: replies[3], | |
| categories: replies[4] | |
| }); | |
| if (items.length == len) | |
| { | |
| callback(err, items); | |
| client.quit(); | |
| } | |
| }); | |
| } | |
| }); | |
| }; |
This file contains hidden or 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
| var express = require('express'), | |
| Resource = require('express-resource'), | |
| app = express.createServer(); | |
| app.resource('item', require('./item'), { format: 'json' }); | |
| app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment