mloughran / em-hiredis

Eventmachine redis client
MIT License
221 stars 63 forks source link

EM::Hiredis.connect creates 2 connection when using just pubsub? #32

Closed devmod closed 10 years ago

devmod commented 10 years ago

Hello,

If im trying to use just the subscription part of pubsub:

redis = EM::Hiredis.connect
redis.pubsub.subscribe("foo") { |msg|
  p [:sub1, msg]
} 

Would Hiredis always create two connections to redis?

Meaning I would have to do this to really close them both ?

redis.pubsub.close_connection
redis.close_connection

Also, a related question- do I have to unsubscribe before closing the pubsub connection?

Thanks!

mloughran commented 10 years ago

That's expected – it's creating a second client for pubsub use – but can see that it's confusing... You can initialize a pubsub client directly, and only create a single connection:

pubsub = EM::Hiredis::PubsubClient.new(<host>, <port>).connect

There's not need to unsubscribe before closing the connection.

devmod commented 10 years ago

Understood- that works. Thanks!