Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper methods for getting channel sizes #66

Open
jwoertink opened this issue Apr 17, 2023 · 2 comments
Open

Helper methods for getting channel sizes #66

jwoertink opened this issue Apr 17, 2023 · 2 comments

Comments

@jwoertink
Copy link
Collaborator

I'm not sure if the rails one has this. I tried searching and couldn't find it, but I feel like I should have an easy way to know exactly how many connects are open on a specific channel.

# no clue what this actually looks like
ChatChannel.fetch_count("room:1") # => 35
EventChannel.fetch_count("events:4") # => 42
@fernandes
Copy link
Collaborator

I remember when monitoring redis for rails actioncable, it uses an internal key as a control pubsub, so it can do some maintenance tasks (like disconnecting all connections for a give client), could take advantage of similar approach, but I'm not confident about how to use it

or maybe could use a redis key to inc/dec on conn/disconn and fetch this number? 🤔

@jwoertink
Copy link
Collaborator Author

Just for some added context here, what I'm currently doing is something like this:

class ChatChannel < Channel
  def subscribe
    increment_count
    stream_from("room:1")
  end
  def unsubscribe
    decrement_count
  end
end

Then elsewhere I have a loop that runs every minute asking what that count is. It would be so much nicer if I could just ask the channel how many are in there, and who they are. Then I wouldn't have to store that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants