openresty / redis2-nginx-module

Nginx upstream module for the Redis 2.0 protocol
http://wiki.nginx.org/HttpRedis2Module
901 stars 142 forks source link

How to know if the redis connected ? #19

Open guowseu opened 11 years ago

guowseu commented 11 years ago

Hi,

Now I want to implement the following function, I want to tell our clients if the data pushed to the redis so that clients can delete local cache. So I want to know if the redis server is ready to accepts requests.

And how to implement this?

Thanks

agentzh commented 11 years ago

Well, just try connecting to the redis server via ngx_lua's TCP/stream cosocket API:

http://wiki.nginx.org/HttpLuaModule#ngx.socket.tcp

Basically, you just need to connect to the server and check the return values (if it is connected, remember closing it or putting it into the connection pool, depending on your needs). Also ensure that you call the settimeout method to set a small enough timeout before calling the connect method.

agentzh commented 11 years ago

If you want to know if some kind of data has been pushed to server, you can just use the Redis pub/sub API: http://redis.io/topics/pubsub (for long polling) or do timed short polling, depending on your requirements.