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

Huy Phan dachuy at gmail.com
Mon Feb 23 14:00:36 MSK 2009


let's go more detail in the code, i used libmemcached and implement
like this : 
static ngx_int_t
ngx_http_memcached_token_handler(ngx_http_request_t *r)
{
    // Some preparation code
      ..................
   
    // 
    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
    size_t value_length;
    uint32_t flags;
    value = memcached_get(memc, key, strlen(key), 
                          &value_length, &flags, &rc1);
    
    if (strcmp(value,"keyvalu1e") == 0)    
        return NGX_OK;
    
    return NGX_HTTP_FORBIDDEN;
}

as I read on google, the line 
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
enable the async request and the code work properly.

But i still think that the code above is in the blocking mode.
How do you think ? 

Another question is that : is there a way to return NGX_AGAIN in the handler (
access phase), and get the engine to call back later ? in this case we can use
upstream with callback mechanism .








More information about the nginx mailing list