nginx_lua_

36 views
Skip to first unread message

Rui Dias

unread,
Dec 6, 2016, 4:58:57 PM12/6/16
to openresty-en
Hello, Im using this configuration and i want to know if it is possible if i get a hit on my memcached on GET command the other part of the code will no run this code should not run{ srcache_fetch GET /memc key=$key;
   
        proxy_pass http://127.0.0.1:80$request_uri;
        set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;
        srcache_request_cache_control off;
        srcache_store PUT /memc key=$key;
}
So what i mean is if memcached has the content dont go to the proxy_pass (server) and dont put the result on it.  
upstream memcached {
    server 127.0.0.1:11211;
    keepalive 32;
}

server {
    listen 8080 default_server;

    root /usr/share/nginx/html;
    index index.fhtml index.fhtm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location = /memc {
        internal;

        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        memc_ignore_client_abort on;

        set $memc_key $arg_key;
        set $memc_exptime 300;

        memc_pass memcached;
    }

    location /memc-stats {
        add_header Content-Type text/plain;
        set $memc_cmd stats;
        memc_pass memcached;
    }

    location / {
        set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;

        srcache_fetch GET /memc key=$key;
        srcache_methods GET;
        srcache_store_statuses 200 301 302;

        proxy_pass http://127.0.0.1:80$request_uri;
        set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;
        srcache_request_cache_control off;
        srcache_store PUT /memc key=$key;
    }

}

Rui Dias

unread,
Dec 6, 2016, 5:01:38 PM12/6/16
to openresty-en

    server_name localhost;

    location = /memc {
        internal;

        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        memc_ignore_client_abort on;

        set $memc_key $arg_key;
        set $memc_exptime 300;

        memc_pass memcached;
    }

    location /memc-stats {
        add_header Content-Type text/plain;
        set $memc_cmd stats;
        memc_pass memcached;
    }

    location / {
        set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;

        srcache_fetch GET /memc key=$key;
        srcache_methods GET;
        srcache_store_statuses 200 301 302;
        ###like a break in this line if the get of cache is a hit  
        proxy_pass http://127.0.0.1:80$request_uri;
        set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;
        srcache_request_cache_control off;
        srcache_store PUT /memc key=$key;
    }

}
Reply all
Reply to author
Forward
0 new messages