From c3d599a58a6d5a86527478b4b712b00134d0547e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 12 Nov 2012 17:31:37 -0800 Subject: Switch from mysql to redis --- app.coffee | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'app.coffee') diff --git a/app.coffee b/app.coffee index d5d4c21c..e74bbdb3 100644 --- a/app.coffee +++ b/app.coffee @@ -24,15 +24,11 @@ app.get('/report', (req, res) -> res.render('report', js: (-> global.js), css: (-> global.css)) ) -app.get('/client/:login', (req, res) -> - connection = require('mysql').createConnection(config.database) - - connection.connect() - connection.query("SELECT name, address, commission, logo FROM users WHERE login = ?", - [req.params.login], (err, rows) -> - res.write(JSON.stringify(rows)) - connection.end() - res.end() +app.get('/client/:client', (req, res) -> + db = require("redis").createClient() + db.hgetall(req.params.client, (err, obj) -> + res.write(JSON.stringify(obj)) + res.end() ) ) @@ -65,24 +61,10 @@ app.get('/ticker', (req, res) -> ) app.post('/create', (req, res) -> - connection = require('mysql').createConnection(config.database) - - connection.connect() - connection.query(""" - INSERT INTO users - (login, name, address, commission) - VALUES - (?, ?, ?, ?) - """, - [ - req.body.login, - req.body.name, - req.body.address, - req.body.commission - ], (err, rows) -> - connection.end() - res.writeHead(302, 'Location': '/' + req.body.login) - res.end() + db = require("redis").createClient() + db.hmset(req.body.login, req.body, -> + res.writeHead(302, 'Location': '/' + req.body.login) + res.end() ) ) -- cgit v1.2.3