gosexy / redis

Redis client for Go that maps the full redis command list into equivalent Go functions.
MIT License
167 stars 44 forks source link

Is there a way to know that the connection has dropped? #18

Closed jeremyricharddavies closed 10 years ago

jeremyricharddavies commented 11 years ago

When a client is connected and using PUBSUB, is there any notification mechanism that the client can use to determine if the connection to redis has dropped?

xiam commented 10 years ago

No, but it sounds very useful. Let's put it on track.

jeremyricharddavies commented 10 years ago

For example, if you have a connection that is SUBSCRIBEd, you can't issue any other commands to determine if the connection is still up. Currently, even another SUBSCRIBE command generates a 'Unexpected response' error.

The redis-cli interface will drop out if the connection drops (tested by stopping the redis-server that it is connected to).

Perhaps there can be some notification on the subscription channel that the connection has closed, provided that hiredis can notify of that event.

crash2burn commented 10 years ago

Without this feature, pub/sub is pretty much useless in this library :) Would be great to hear if its possible to add

xiam commented 10 years ago

It would be indeed useful. Sorry for the awful delay, I took a small break but now that I'm getting back to open source I can get my hands on this :-).

crash2burn commented 10 years ago

All good - thanks for the update!

xiam commented 10 years ago

Please see the experimental branch and the provided example: https://github.com/gosexy/redis/blob/experimental/_examples/test-server-disconnection/main.go

xiam commented 10 years ago

Merged into the master branch :-).

From now on, the Subscribe() method will return and error value (redis.ErrEOF) when the connection is dropped.

crash2burn commented 10 years ago

Nice, will give it a go, thanks!