From ccc57b0d71cfffbd92d37dedac9fdf4cdcfcf8da Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 22 Apr 2013 18:14:28 +0000 Subject: [PATCH] forgot to add redis.js --- public/templates/header.tpl | 4 +-- src/redis.js | 59 +++++++++++++++++++++++++++++++++++++ src/webserver.js | 2 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/redis.js diff --git a/public/templates/header.tpl b/public/templates/header.tpl index c392fd2253..d3d3ba68b1 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -29,9 +29,9 @@ templates_init(); - var rootUrl = document.location.protocol + '//' + (document.location.hostname || document.location.host), + var rootUrl = document.location.protocol + '//' + (document.location.hostname || document.location.host) + (document.location.port ? ':'+document.location.port : ''), content = null; - + console.log(rootUrl); $('document').ready(function() { if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers diff --git a/src/redis.js b/src/redis.js new file mode 100644 index 0000000000..100e6a70c6 --- /dev/null +++ b/src/redis.js @@ -0,0 +1,59 @@ +(function(RedisDB) { + var PRODUCTION = false, + ERROR_LOGS = true, + + redis = require('redis'), + db = redis.createClient(); + + // todo (holy cow): append,auth,bgrewriteaof,bgsave,bitcount,bitop,blpop,brpop,brpoplpush,client kill,client list,client getname,client setname,config get,config set,config resetstat,dbsize,debug object,debug segfault,decrby,del,discard,dump,echo,eval,evalsha,exec,exists,expire,expireat,flushall,flushdb,getbit,getrange,getset,hdel,hexists,hget,hgetall,hincrby,hincrbyfloat,hkeys,hlen,hmget,hmset,hset,hsetnx,hvals,incrby,incrbyfloat,info,keys,lastsave,lindex,linsert,llen,lpop,lpush,lpushx,lrange,lrem,lset,ltrim,mget,migrate,monitor,move,mset,msetnx,multi,object,persist,pexpire,pexpireat,ping,psetex,psubscribe,pttl,publish,punsubscribe,quit,randomkey,rename,renamenx,restore,rpop,rpoplpush,rpush,rpushx,sadd,save,scard,script exists,script flush,script kill,script load,sdiff,sdiffstore,select,setbit,setex,setnx,setrange,shutdown,sinter,sinterstore,sismember,slaveof,slowlog,smembers,smove,sort,spop,srandmember,srem,strlen,subscribe,sunion,sunionstore,sync,time,ttl,type,unsubscribe,unwatch,watch,zadd,zcard,zcount,zincrby,zinterstore,zrange,zrangebyscore,zrank,zrem,zremrangebyrank,zremrangebyscore,zrevrange,zrevrangebyscore,zrevrank,zscore,zunionstore + // done :^) get, set, incr, decr + + function return_handler(error, data, callback, error_handler) { + if (error !== null) { + if (error_handler !== null) { + error_handler(error); + } else if (PRODUCTION === false) { + throw new Exception('RedisDB Error: ' + error); + } else if (ERROR_LOGS === true) { + console.log('RedisDB Error: ' + error); + } + } else { + callback(data); + } + } + + RedisDB.set = function(key, value) { + db.set(key, value); + }; + + RedisDB.get = function(key, callback, error_handler) { + db.get(key, function(error, data) { + return_handler(error, data, callback, error_handler); + }); + }; + + // Atomic Operations + RedisDB.incr = function(key, callback, error_handler) { + db.incr(key, function(error, data) { + if (callback) { + return_handler(error, data, callback, error_handler); + } + }); + }; + + RedisDB.decr = function(key) { + db.decr(key); + }; + + // Lists + RedisDB.lpush = function(key, item) { + db.lpush(key, item); + } + + RedisDB.lrange = function(key, start, end, callback, error_handler) { + db.lrange(key, start, end, function(error, data) { + return_handler(error, data, callback, error_handler); + }); + } + +}(exports)); \ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index 8c22b763e2..dac82c2d49 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -46,7 +46,7 @@ var express = require('express'), }); }); - app.listen(80); + app.listen(4567); } }(WebServer));