Permalink
Browse files

adding redis store for files

  • Loading branch information...
Sam Breed
Sam Breed committed Apr 9, 2012
1 parent 0907a04 commit b1ffe3d5ea64d91f3456e2c815f5d1cd9f799318
Showing with 16 additions and 4 deletions.
  1. +3 −1 package.json
  2. +13 −3 server.js
View
@@ -10,7 +10,9 @@
"union": "0.1.7",
"flatiron": "0.1.16",
"socket.io": "0.9.5",
- "ecstatic": "0.1.6"
+ "ecstatic": "0.1.6",
+ "hiredis": "0.1.14",
+ "redis": "0.7.1"
},
"devDependencies": {
"api-easy": "0.3.2",
View
@@ -10,6 +10,7 @@ ________________________________________________________________
var
fs = require('fs'),
crypto = require('crypto'),
+ redis = require('redis'),
flatiron = require('flatiron'),
ecstatic = require('ecstatic'),
path = require('path'),
@@ -45,6 +46,9 @@ app.router.get('*', function() {
});
var memory = {};
+
+var client = redis.createClient();
+
var socket;
app.router.post('/files', function(){
@@ -54,14 +58,16 @@ app.router.post('/files', function(){
hash.update( body.body + body.name );
body.id = hash.digest('hex').slice(0,8);
- memory[body.id] = body;
+
+ client.set(body.id, JSON.stringify(body), redis.print);
this.res.json(body);
});
app.router.put('/files/:id', function(){
var body = this.req.body;
- memory[body.id] = body;
+
+ client.set(body.id, JSON.stringify(body), redis.print);
if( socket !== undefined ){
socket.emit(body.id, body);
@@ -71,7 +77,11 @@ app.router.put('/files/:id', function(){
});
app.router.get('/files/:id', function( id ){
- this.res.json( memory[id] );
+ var _this = this;
+
+ client.get(id, function(err, reply){
+ _this.res.json( JSON.parse( reply.toString() ) );
+ });
});
app.start(process.env.PORT || 3000);

0 comments on commit b1ffe3d

Please sign in to comment.