is it possible to connect to memcached and check in access phase?

Manlio Perillo manlio_perillo at libero.it
Sun Feb 22 21:30:36 MSK 2009


Huy Phan ha scritto:
> I'm trying to build a nginx module for the need of my workflow :
> In access phase :
> 1. Connect to  the memcached and get value for key "abcxyz"
> 2. If the value is 1, return NGX_HTTP_OK ( 200 )
> 2. If the value is 0, return NGX_HTTP_FORBIDDEN ( 403 )
> 
> As far as I know, upstream is the only way to connect to memcached, but 
> it's using callback mechanism ( asynchronous request ) .

It is not the only way.
It is just the only method implemented, since memcached is used for 
generated content.

> Is it possible to connect to the memcached and wait for result ( 
> synchronous ) , then return corresponding code right inside handler 
> function of access phase ?
> 

Of course it is possible, you just have to use or implement a memcached 
client.

But doing it synchronously will hurt nginx performance.
You need to implement an asynchronous memcached client.

See the asynchronous DNS resolver, for an example on how to do it (but 
it is rather complex).



Manlio Perillo





More information about the nginx mailing list