Permalink
Browse files

Adding redis brain to ob.

  • Loading branch information...
uchouhan committed Apr 21, 2012
1 parent b4c7c59 commit c8b5fe5628bff4237f085032baf617e1c7cf321d
Showing with 27 additions and 0 deletions.
  1. +27 −0 redis-brain.coffee
View
@@ -0,0 +1,27 @@
+Url = require 'url'
+Redis = require 'redis'
+
+module.exports = (robot) ->
+ info = 'redis://localhost:6379'
+ client = Redis.createClient(info.port, info.hostname)
+
+ if info.auth
+ client.auth info.auth.split(":")[1]
+
+ client.on "error", (err) ->
+ robot.logger.error err
+
+ client.on "connect", ->
+ robot.logger.info "Successfully connected to Redis"
+
+ client.get "hubot:storage", (err, reply) ->
+ if err
+ throw err
+ else if reply
+ robot.brain.mergeData JSON.parse(reply.toString())
+
+ robot.brain.on 'save', (data) ->
+ client.set 'hubot:storage', JSON.stringify data
+
+ robot.brain.on 'close', ->
+ client.quit()

0 comments on commit c8b5fe5

Please sign in to comment.