Ask A Question

Notifications

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:

ActionCable.server.pubsub.redis_connection_for_subscriptions.sadd
ActionCable.server.pubsub.redis_connection_for_subscriptions.rem
ActionCable.server.pubsub.redis_connection_for_subscriptions.smembers

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.

First:

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 ?

Second:

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?

Third:

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 = Redis.new(url: ENV['REDIS_URL')

and replacing the initial code by:

$redis.sadd
$redis.srem
$redis.smembers

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 :)

Reply
Join the discussion
Create an account Log in

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

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

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