Skip to content

Commit

Permalink
redis brain using new eventemitter-powered robot.brain in hubot maste…
Browse files Browse the repository at this point in the history
…r (pending 1.1.0)
  • Loading branch information
technoweenie authored and jonmagic committed Oct 27, 2011
1 parent f130172 commit dba5204
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/scripts/redis_brain.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# sets up hooks to persist the brain into redis.
module.exports = (robot) ->
info = Url.parse process.env.REDISTOGO_URL || 'redis://localhost:6379'
client = Redis.createClient(info.port, info.hostname)

if info.auth
client.auth info.auth.split(":")[1]

client.on "error", (err) ->
console.log "Error #{err}"

client.on "connect", ->
console.log "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', data

robot.brain.on 'close', ->
client.quit()

0 comments on commit dba5204

Please sign in to comment.