All threads / Heroku RedisCloud connexions on "Realtime Online User Tracking with ActionCable"
Ask A Question


You’re not receiving notifications from this thread.

Heroku RedisCloud connexions on "Realtime Online User Tracking with ActionCable"

Nathan Chalot asked in Rails

Hi all,
I'm running in a weird issue.

Following the Realtime Online User Tracking with ActionCable screencast, in an app using rails 5.2 I used:


to add, remove and retrieve a users ids list from redis.

Deploying to staging on heroku, using the rediscloud addon for redis, I had the following issue with this implementation, each of this call was instantiating a new connexion to redis, so that I was hitting the rediscloud connexion limit really fast.


does anyone has this kind of issue ? I cannot replicate the output I got from redis cloud in redis-cli CLIENT LIST in my local env. So I'm wondering if it has something to do with redis cloud ?


I read here to use ActionCable.server.pubsub.send(:redis_connection) to get the ActionCable connexion but I looked into the code for the ActionCable Redis adapater and, I'm not totally sure but think that's what the initial method redis_connection_for_subscriptions does.

Does ActionCable.server.pubsub.redis_connection_for_subscriptions indeed instantiate a new connexion each time it is called?


I'm kind of worried about my current solution:

I resolved the problem by doing inspired by the rediscloud doc this in an initializer

$redis = ENV['REDIS_URL')

and replacing the initial code by:


It now works as expected and I don't reach the connexion limit, but I'm quite not sure about the use of a global variable.

If anybody has an insight / a better way to solve this I would really appreciate it.

thanks for reading that long post :)

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.