Permalink
Browse files

* Restore on-disk JSON DB fallback if Redis is not installed

  • Loading branch information...
1 parent 5289ef9 commit 546220a3664783a8e4bd2ce85744f32a385f5775 @audreyt committed Mar 30, 2013
Showing with 35 additions and 29 deletions.
  1. +22 −17 db.js
  2. +13 −12 src/db.ls
View
39 db.js
@@ -19,36 +19,41 @@
redisPort == null && (redisPort = 6379);
dataDir == null && (dataDir = process.cwd());
redis = require('redis');
- makeClient = function(){
+ makeClient = function(cb){
var client;
client = redis.createClient(redisPort, redisHost);
if (redisPass) {
client.auth(redisPass, function(){
return console.log.apply(console, arguments);
});
}
+ if (cb) {
+ client.on('connect', cb);
+ }
return client;
};
this.io.configure(function(){
- var RedisStore, redisPub, redisSub, redisClient, store;
+ var RedisStore, redisClient;
RedisStore = require('zappajs/node_modules/socket.io/lib/stores/redis');
- redisPub = makeClient();
- redisSub = makeClient();
- redisClient = makeClient();
- store = new RedisStore({
- redis: redis,
- redisPub: redisPub,
- redisSub: redisSub,
- redisClient: redisClient
+ redisClient = makeClient(function(){
+ var redisPub, redisSub, store;
+ redisPub = makeClient();
+ redisSub = makeClient();
+ store = new RedisStore({
+ redis: redis,
+ redisPub: redisPub,
+ redisSub: redisSub,
+ redisClient: redisClient
+ });
+ this$.io.set('store', store);
+ this$.io.enable('browser client etag');
+ this$.io.enable('browser client gzip');
+ this$.io.enable('browser client minification');
+ return this$.io.set('log level', 5);
});
- this$.io.set('store', store);
- this$.io.enable('browser client etag');
- this$.io.enable('browser client gzip');
- this$.io.enable('browser client minification');
- return this$.io.set('log level', 5);
+ return redisClient.on('error', function(){});
});
- db = makeClient();
- db.on('connect', function(){
+ db = makeClient(function(){
db.DB = true;
return console.log("Connected to Redis Server: " + redisHost + ":" + redisPort);
});
View
@@ -16,26 +16,27 @@
dataDir ?= process.cwd!
require! \redis
- make-client = ->
+ make-client = (cb) ->
client = redis.createClient redisPort, redisHost
if redisPass
client.auth redisPass, -> console.log ...arguments
+ client.on \connect cb if cb
return client
@io.configure ~>
RedisStore = require \zappajs/node_modules/socket.io/lib/stores/redis
- redis-pub = make-client!
- redis-sub = make-client!
- redis-client = make-client!
- store = new RedisStore { redis, redis-pub, redis-sub, redis-client }
- @io.set \store store
- @io.enable 'browser client etag'
- @io.enable 'browser client gzip'
- @io.enable 'browser client minification'
- @io.set 'log level', 5
+ redis-client = make-client ~>
+ redis-pub = make-client!
+ redis-sub = make-client!
+ store = new RedisStore { redis, redis-pub, redis-sub, redis-client }
+ @io.set \store store
+ @io.enable 'browser client etag'
+ @io.enable 'browser client gzip'
+ @io.enable 'browser client minification'
+ @io.set 'log level', 5
+ redis-client.on \error ->
- db = make-client!
- db.on \connect ~>
+ db = make-client ~>
db.DB = true
console.log "Connected to Redis Server: #redisHost:#redisPort"

0 comments on commit 546220a

Please sign in to comment.