14

In my app I dynamically create new pubsub channels and there might be too many like 5k per day. According to my app's requirements any channel is used for at most 5minutes.

Considering this situation, thousands of unused channels will be present in the app in a week. So how can I delete unused channels or should I even delete them. Do they stored in memory? What happens to the messages published via them, do they stay on the redis' memory?

thanks

destan
  • 4,301
  • 3
  • 35
  • 62
  • After "the 5 minutes" your app send an `UNSUBSCRIBE` command? – byterussian May 16 '13 at 12:08
  • my clients are web clients over socket.io so the end user may shut the browser tab suddenly and I might not know if he's still connected or not. Maybe I could handle this by catching the socket.io timeouts or something but the main thing is that is it guaranteed that `UNSUBSCRIBE`ing all the subscribers result in deleting the channel? – destan May 16 '13 at 13:53
  • Not sure, try. I remember that if a channel have zero subscribers is deleted. For the message problem, after are send the messages and are received it doesn't exists anymore. – byterussian May 16 '13 at 14:35
  • @byterussian let's say I've tried, how would I confirm that it's get deleted? – destan May 16 '13 at 20:41
  • 1
    inside redis-cli: `INFO stats` check pubsub_channels – byterussian May 16 '13 at 21:02

1 Answers1

24

Channels are ambient. They only exist while there are subscriptions. So: either call [P]UNSUBSCRIBE from the connections that subscribed, or close the connections that subscribed.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • thanks for the answer, can you specify any source to indicate that? I couldn't find such detail in the docs. – destan May 16 '13 at 20:37
  • 1
    @destan you could measure "info stats" before and after (which describes the subscription counts) - close enough? Or you could read the source? But basically I know "by speaking to the authors" - lo tech I'm afraid – Marc Gravell May 16 '13 at 21:13