Skip to content

Commit

Permalink
Merge pull request #4 from 100ideas/redistogo
Browse files Browse the repository at this point in the history
properly set auth token and no_ready_check for heroku redistogo
  • Loading branch information
technicalpickles committed Jun 6, 2015
2 parents 248aa69 + 154ee33 commit c7d8f85
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/redis-brain.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ module.exports = (robot) ->
'redis://localhost:6379'

if redisUrlEnv?
robot.logger.info "Discovered redis from #{redisUrlEnv} environment variable"
robot.logger.info "hubot-redis-brain: Discovered redis from #{redisUrlEnv} environment variable"
else
robot.logger.info "Using default redis on localhost:6379"
robot.logger.info "hubot-redis-brain: Using default redis on localhost:6379"


info = Url.parse redisUrl, true
client = Redis.createClient(info.port, info.hostname)
info = Url.parse redisUrl, true
client = if info.auth then Redis.createClient(info.port, info.hostname, {no_ready_check: true}) else Redis.createClient(info.port, info.hostname)
prefix = info.path?.replace('/', '') or 'hubot'

robot.brain.setAutoSave false
Expand All @@ -45,20 +45,20 @@ module.exports = (robot) ->
if err
throw err
else if reply
robot.logger.info "Data for #{prefix} brain retrieved from Redis"
robot.logger.info "hubot-redis-brain: Data for #{prefix} brain retrieved from Redis"
robot.brain.mergeData JSON.parse(reply.toString())
else
robot.logger.info "Initializing new data for #{prefix} brain"
robot.logger.info "hubot-redis-brain: Initializing new data for #{prefix} brain"
robot.brain.mergeData {}

robot.brain.setAutoSave true

if info.auth
client.auth info.auth.split(":")[1], (err) ->
if err
robot.logger.error "Failed to authenticate to Redis"
robot.logger.error "hubot-redis-brain: Failed to authenticate to Redis"
else
robot.logger.info "Successfully authenticated to Redis"
robot.logger.info "hubot-redis-brain: Successfully authenticated to Redis"
getData()

client.on "error", (err) ->
Expand All @@ -68,7 +68,7 @@ module.exports = (robot) ->
robot.logger.error err.stack

client.on "connect", ->
robot.logger.debug "Successfully connected to Redis"
robot.logger.debug "hubot-redis-brain: Successfully connected to Redis"
getData() if not info.auth

robot.brain.on 'save', (data = {}) ->
Expand Down

0 comments on commit c7d8f85

Please sign in to comment.